When you install a new Ubuntu release on your system, it sets things up to using DHCP by default. It’s a handy default that will work for most people but if you intend on running this particular machine as a serer (NAS box, squeezebox server, print server…), you may find more convenient to have a static IP address which can easily be mapped to a name without the use of a DNS server. The instructions below are based on ubuntu (10.x / 11.x and older/newer versions).
How to setup a static / fixed IP address
- cd /etc/network
- sudo cp interfaces interfaces.DHCP (always good to make a copy of original files)
- sudo emacs intervaces (substitute emacs for your favorite editor: vi, gedit …)
Replace the content of the file with the following:
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.X (replace X with your host address) netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1
Here we assume a home network of: 192.168.1.0 (most common behind NAT firewalls/routers). Substitute with your own internal home network number. Next follow those steps:
- First find out what your current IP Address is: sudo ifconfig | grep inet
- Restart networking: sudo /etc/init.d/networking restart
- You will now be kicked out of the server if you had connected via ssh/telnet.
- Check that the new IP Address is is now effective: sudo ifconfig | grep inet
- Then you must setup a static DNS server entry:
How to setup Static DNS server entry:
Since you are no longer getting your IP Address from DHCP, you also have to setup a static entry for your DNS server. In most cases, people don’t run an in-house DNS server and rely instead on their ISP to provide one. Most home routers/firewalls acts act as an intermediary DNS server by relaying all requests to the upstream ISP configured DNS server. In my case, using Cox or Comcast cable as the ISP, my router obtains an IP address using DHCP which also configures DNS server info in my router.
To configure the static DNS server entry for my host: (again my editor is emacs)
- sudo emacs /etc/resolv.conf
- Leave only the following line in the file:
nameserver 192.168.1.1 (substitute for the IP address of your own router)
Configure /etc/hosts with our your home devices:
Most people don’t bother to run a DNS server internally (not worth it for 2-5 machines!). the simplest way to map your host names (PCs, printers, Boxee box etc…) is to edit the “hosts” file:
sudo emacs /etc/hosts
Here is what mine looks like:
127.0.0.1 localhost 192.168.1.45 greenbug 192.168.1.50 jumbo 192.168.1.1 tomato 192.168.1.2 unas 192.168.1.40 vonage-biz 192.168.1.41 vonage-home 192.168.1.201 BigBubba-Printer # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
With the last lines were already in the hosts file, setup by ubuntu to support IPV6 (leave it alone). These three simple setups should have your system properly configured with a static IP address.
NOTE: I also make a copy of the /etc/network/interfaces file as interfaces.STATIC to have a backup of this configuration. This way if I travel with my laptop and need to access DHCP at the hotel room, I can just copy the interfaces.DHCP and restart my networking (or reboot) and the system then behaves as a normal dhcp client.