Custom Search

Ubuntu server static ip

There are several ways to manage Ubuntu server ip address. One way is by using traditional Linux tool, the ifconfig command. The other way is by manually edit the /etc/network/interfaces file.

Here is an example of a default Ubuntu /etc/network/interfaces file:

# 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

/etc/network/interfaces (END)


You can use text editor such as vim to set Ubuntu server static ip. Here is a vim text editor's guide if you need one. Change Ubuntu /etc/network/interfaces dhcp to static like an example below:

# 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 static
address 192.168.1.3
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
# dns-* options are implemented by the resolvconf package,
if installed
dns-nameservers 192.168.1.1
dns-search musang.com
/etc/network/interfaces (END)


This is an example of Ubuntu server static ip configuration from VMWare Ubuntu server guest in Windows XP. You can copy the configuration above and just change the ip address to yours. Save the /etc/network/interfaces file and exit.

You need to restart the network before the changes take effect. To restart network in Ubuntu, use the command below:

luzar@ubuntu:~$ sudo /etc/init.d/networking restart
[sudo] password for luzar:
* Reconfiguring network interfaces... [ OK ]
luzar@ubuntu:~$

You can check the ip address to confirm the changes with ifconfig command. Here is an example:

luzar@ubuntu:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:d2:1d:9b
inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fa80::20b:29fc:fbd2:1b9b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:408 errors:0 dropped:0 overruns:0 frame:0
TX packets:321 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:37334 (36.4 KB) TX bytes:37704 (36.8 KB)
Interrupt:16 Base address:0x2000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

luzar@ubuntu:~$


That's all. Your network should work now. You can check your networking status with ping command. You can try pinging your gateway or other computer in your network.

Use ping command to check your network:


luzar@ubuntu:~$ ping -c3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=128 time=0.130 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=128 time=0.126 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=128 time=0.132 ms

--- 10.21.35.160 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.126/0.129/0.132/0.009 ms
luzar@ubuntu:~$


If your Ubuntu server is like mine, I mean Ubuntu server as a VMWare guest operating system in Windows xp, using nat to share Ethernet device, then maybe you have to wait a few seconds before the networking takes effect. Sometimes the network is not working when you start the virtual server. Just restart eth0 and testing your connection again.

1 comment:

  1. how do i set a static ip when i installed ubuntu on vmware?

    i can set the static ip in ubuntu but it's not allowing me on the net.

    i have been @ this for weeks can u pls help

    ReplyDelete

Please keep comment relevant and strictly no spam will be tolerated. Thank you.