4

On my local network (at home), I have a Linux machine called A, connected to the Internet through a modem. I want to give A a static local IP address when it's at home, but a dynamically allocated one when it's not. How would I achieve this?

I think one way I could do this is to check my public IP address and see whether it is within my ISP's allocation range, but this seems unelegant and I don't know how to do it. I could also check if my modem exists between me and the Internet, but again, I do not know how.

I would appreciate any suggestions. Thanks for your attention!

4
  • You can probably bind the internal IP address to the system from your router. This way you don't need to change any system settings. If you want help with this we would need your router model. Apr 17, 2014 at 11:02
  • My connection is actually wireless router -> modem -> ISP. The modem is provided by the ISP, and the router is a Linksys WRT54G with default firmware.
    – shardulc
    Apr 17, 2014 at 11:06
  • I'd add a comment, but cant. I hate to tell you, so I'll let this post I know this works on the newer models because I'm using it for my Roku. Your ISP's custom firmware is used to prevent customers from using a DHCP leased routable IP to mimic a static connection to the Internet. This firmware is in their edge routers, not your router.
    – eyoung100
    Apr 17, 2014 at 14:10
  • Not an answer to your question, but I found it easier to set up DHCP on your home router, so that you can use dynamic IP allocation everywhere. I'd recommend this as the first choice.
    – RomanSt
    Apr 17, 2014 at 15:16

1 Answer 1

7

It is easier to configure your router than your computer. For this to work, you need the mac address of your wireless card. This is commonly referred to 'Hardware address' and you can see it in control panel of by typing ifconfig in your console.

When you obtain your MAC address (it will look something like AA:BB:CC:DD:EE:FF) you can then configure it in your router. The option is probably under DHCP configuration called Static leases.

There you can assign fixed ip to a mac address. So, for the mac address you put the one you just obtained, and for the IP you put the desired IP.

After that, even though your computer is set to automatic configuration, it will always get the fixed IP from the router.

6
  • My router has blocked DHCP static leases (ISP uses custom firmware). What would be the options there?
    – jnovacho
    Apr 17, 2014 at 12:41
  • Just to clarify, we are talking about wireless router that you have before your modem, right? Your ISP provided you with a wifi router?
    – dkasipovic
    Apr 17, 2014 at 12:42
  • No, the wifi router is my own while the ADSL modem is provided by the ISP. My machine is connected to the router, which is connected to the modem.
    – shardulc
    Apr 17, 2014 at 14:59
  • So how can "ISP use custom firmware"? All the settings that I mentioned are located in your wifi router (which you say is yours).
    – dkasipovic
    Apr 17, 2014 at 15:21
  • @DKasipovic Sorry for confusion, I'm not OP. I have cable modem, with WiFi and my ISP has custom firewall. So I was trying to discuss other possibilities.
    – jnovacho
    Apr 17, 2014 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .