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.

sudo nano /etc/network/interfaces

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

# This file describes the network interfaces available on your system
# and how to activate them, for more information, see interfaces(5).
auto lo
iface lo inet loopback

# The primary network interface

auto eth0
iface eth0 inet static
address 192.168.1.15
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0
gateway 192.168.1.1

Next you need to edit the resolv.conf file and add your own DNS setting, as you can see below I use nano as my default editor, you can use anything your comfortable with.

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 bind on 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.

sudo nano /etc/hosts

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.

127.0.0.1          localhost
192.168.1.10    workstation.linuxhome.co.uk   workstation
192.168.1.15    orion.linuxhome.co.uk            orion
192.168.1.20    squeezebox.linuxhome.co.uk   squeezebox

# The following lines are desirable for IPv6 capable hosts
::1         ip6-localhost ip6-loopback
fe00::00 ip6-localnet
ff00::00 ip6-mcastprefix
ff02::01 ip6-allnodes
ff02::02 ip6-allrouters
ff02::03 ip6-allhosts

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

sudo /etc/init.d/networking restart

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

billy@orion:~$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:30:18:a8:93:4d
inet addr:192.168.1.15  Bcast:192.168.1.255  Mask:255.255.255.0
inet6 addr: fe80::230:18ff:fea8:934d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:893 errors:0 dropped:371674228 overruns:0 frame:0
TX packets:304 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:77902 (76.0 KB)  TX bytes:67134 (65.5 KB)
Interrupt:221

billy@orion:~$

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.

About billy

Senior IT Technician working in Edinburgh, Scotland.
This entry was posted in Linux, Personal and tagged , . Bookmark the permalink.

One Response to 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

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>