Tuesday, September 4, 2012

Set A Static IP On Ubuntu

To change my IP address on Ubuntu from DHCP to static IP, I do following step. First, open file /etc/network/interfaces. I'm not a fan of vi/vim, I'm using nano (or editor in MC)
sudo nano /etc/network/interfaces

You will find something like this:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

To make it static, I change to (based on my network):
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.191
netmask 255.255.255.0
gateway 192.168.1.1

Restart the interface:
sudo ifdown eth0
sudo ifup eth0

And with ifconfig, voilĂ :


But, I still have problem later:


The system cannot resolve DNS. To resolve this, I re-edit /etc/network/interfaces, and add entry of dns-nameservers. So the complete /etc/network/interfaces will looks like:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.191
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1

Done, restart the interface again (ifdown and ifup), now I can browse internet.

No comments:

Post a Comment