Problem
I want to ensure my linux server always has the same IP address. If it still wants to use dhclient to find a dynamic ip address, and the nameservers, then that’s ok too.
Solution
By setting an “alias” for the fixed address in dhclient it will answer to both the static ip address you want and any dhcp address leased from a dhcp server.
Method
Edit /etc/dhcp3/dhclient.conf to include something like:
alias {
interface "eth0";
fixed-address 192.168.1.101;
option subnet-mask 255.255.255.255;
}
Which tells dhclient that whatever ip address it gets for eth0, 192.168.1.101 is also its ip address. So it will answer to two ip addresses simultaneously.
Restart the network and you’re done…
john@lappy:/etc$ sudo /etc/init.d/networking restart
[sudo] password for john:
* Reconfiguring network interfaces...
...
DHCPACK of 192.168.1.4 from 192.168.1.254
bound to 192.168.1.4 -- renewal in 120670 seconds.
[ OK ]
john@lappy:/etc$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0d:60:8a:35:92
inet addr:192.168.1.4 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20d:60ff:fe8a:3592/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10012 errors:0 dropped:0 overruns:0 frame:0
TX packets:5789 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:13138975 (13.1 MB) TX bytes:565365 (565.3 KB)
eth0:0 Link encap:Ethernet HWaddr 00:0d:60:8a:35:92
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:56 errors:0 dropped:0 overruns:0 frame:0
TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3850 (3.8 KB) TX bytes:3850 (3.8 KB)
john@lappy:/etc$
Story
Once upon a time every computer had a static IP address and setting it was a trivial text edit or command line task. But today I had trouble getting Ubuntu Linux (Intrepid) to do it. A simple edit of /etc/network/interfaces no longer seems to work as expected. With a whiff of Microsoft “helpfulness” a irrepressible effort now goes into ensuring Ubuntu is dummy proofed to find an IP address for itself. Me trying to tell it not to find an IP address I found was working against the flow of traffic.