Setting up a static IP on a linux box

Setting up a static IP address

home-network

Home Network

My wireless gateway has a static external IP address (Provided by my ISP), this enables me to  have forward and reverse DNS resolution. Forward resolution is provided by dyndns.com and reverse dns resolution is provided by my ISP Zen Internet.

Home Network IP Allocation
192.168.1.1 – 192.168.1.20 Static
IP address allocation
Routers
Servers
Printer
192.168.1.21 – 192.168.1.240 Dynamic
IP address allocation via DHCP
Laptops
Personal Data Assistants (PDA’s)
XBox 360 etc..

You need to give your server (mine is called orion) and a valid static IP address, like most home users, my home network uses a Class C Private Address Space and NAT (Network Address Translation). Both of which are provided by my Wireless Gateway, which also provides DHCP for my laptop and other PDA’s.

First, I give the pc an IP address, subnet mask and gateway by editing the interfaces file using nano, you can of course us vi if thats what you comfortable with.

You need to add your own network address, netmask and gateway.

Update 01/11/12

If you are using a newer versions of   Ubuntu (12.04 LTS), then resolve.conf is now updated by the resolver process. So instead of amending the resolv.conf file below, you would just append “dns-nameserver 8.8.8.8, 192.168.1.15” to the /etc/network/interfaces file above. See Ubuntu Network Configuration for more details.

sudo nano /etc/resolv.conf
Once your preferred editor opens the file you want to enter the following information (changing your addresses where necessary) these nameserver are your ISP’s DNS server:

DNS is provided below by https://www.opendns.com/ , you can either use
# these settings or you can replace them with your own ISP’s DNS servers.
#
# My internal network is called linuxhome.co.uk so I also include the following.
# You of course probably won’t have to include the following.
# search linuxhome.co.uk
nameserver 208.67.222.222
nameserver 208.67.220.220

Now it’s time to edit the hosts file at /etc/hosts, I have a very small network indeed, you can add as many internal hosts to this as you want to resolve. I only want the server to resolve it’s own IP and the other 2 devices on my internal network, any other external machines will be resolved by external DNS as usual. You could of course install bindon your own Ubuntu Linux server and point the above to “nameserver 127.0.0.1” but I personally don’t think it’s worth the effort involved.

Mine looks like this, yours of course will depend on what you’ve called your server and the IP you’ve allocated to the server.

Now it’s time to bring up the network interface.

All going well you should get the following when you type ifconfig:

To test properly, try to ping the default gateway and an external address. Good luck!

Heres another howto that I’ve written called Setting up NFS on a home linux box. I’ve written this mostly as a reminder to myself, but feel free to use it if it helps.

One thought on “Setting up a static IP on a linux box

  1. Pingback: The Internet made me do it! » Configuring a static IP address on Lucid Lynx

Leave a Reply