Posted by: isaraffee | April 10, 2010

Setting IP address on Ubuntu

Setting IP address on Ubuntu

To set a temporary IP address on Ubuntu type

# ifconfig eth0 172.16.0.2 netmask 255.255.0.0 broadcast 172.16.255.255 up

Verify the network connections.

# ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:16:d3:43:12:02

inet addr:172.16.0.2 Bcast:172.16.255.255 Mask:255.255.0.0

inet6 addr: fe80::216:d3ff:fe43:1202/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

<output truncated for brevity>

Test the configuration by pinging its IP address

root@ismail-laptop:~# ping 172.16.0.2

PING 172.16.0.2 (172.16.0.2) 56(84) bytes of data.

64 bytes from 172.16.0.2: icmp_seq=1 ttl=64 time=0.054 ms

64 bytes from 172.16.0.2: icmp_seq=2 ttl=64 time=0.039 ms

^C

— 172.16.0.2 ping statistics —

2 packets transmitted, 2 received, 0% packet loss, time 999ms

rtt min/avg/max/mdev = 0.039/0.046/0.054/0.010 ms

This IP address will be gone once you reboot the machine. To set the IP address permanently follow these steps.

Setting IP address on Ubuntu via Configuration file

If the Ubuntu Server installer has set your server to use DHCP, you will want to change it to a static IP address so that people can actually use it.

Changing this setting without a GUI will require some text editing, but that’s classic linux, right?

Let’s open up the /etc/network/interfaces file. I’m going to use vi, but you can choose a different editor

sudo vi /etc/network/interfaces

For the primary interface, which is usually eth0, you will see these lines:

auto eth0
iface eth0 inet dhcp

As you can see, it’s using DHCP right now. We are going to change dhcp to static, and then there are a number of options that should be added below it. Obviously you’d customize this to your network.

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

The auto directive identifies the network interface to be configured, in this case the loopback adapter as noted by the lo label.

Auto lo

Without the auto directive, the specifiied interface is not activated the next time you type the /etc/init.d/networking restart or the ifup -a commands.

iface lo inet loopback

The auto lo directive also need the directive shown above. The iface directuve applies Ipv4 networking as defined by the inet directive (Ipv6 would be configured with inet6), along with the loopback address, to the loopback adapter lo.

If you are using DNS to resolve IP addresses to machine names, you may want to add the DNS server (name servers) by editing the resolv.conf file:

sudo vi /etc/resolv.conf

On the line ‘nameserver xxx.xxx.xxx.xxx’ replace the x with the IP of your name server.

Now we’ll just need to restart the networking components:

sudo /etc/init.d/networking restart

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: