Network interface is the one of the basic setup in a server or workstation to get your machine connected to outside world. This article will guide you configure the network interface in Ubuntu 12.04 in both dynamic and static.
Pre-requisite:
You should know basic operation of vi editor in order to follow this guide
Dynamic IP address:
1. Open network interface file with vi editor
# vi /etc/network/interfaces
|
2. Look for the line with iface eth0
3. Modify the line with following
iface eth0 inet dhcp
|
4. The actual configuration for interface eth0 should be this
auto eth0
iface eth0 inet dhcp
|
5. If you have more than 1 network interface, let’s say eth0 and eth1, and you wish to configure both of them as dynamic IP, the configuration would be as followed.
auto eth0
iface eth0 inet dhcp
auto eth1
iface eth1 inet dhcp
|
6. Save the file and close vi editor
7. Type the following command to restart your network settings
# /etc/init.d/networking restart
|
8. Type the following command to check your newly allocated IP address
# ifconfig eth0
|
9. You should see an output similar like following
eth0 Link encap:Ethernet HWaddr 00:0c:29:17:fe:5f
inet addr:192.168.223.128 Bcast:192.168.223.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe17:fe5f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17637 errors:0 dropped:0 overruns:0 frame:0
TX packets:8875 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25244876 (25.2 MB) TX bytes:502639 (502.6 KB)
Interrupt:19 Base address:0x2000
|
Static IP address:
1. Open network interface file with vi editor
# vi /etc/network/interfaces
|
2. Modify the eth0 section with following. (Key in the address, subnet and gateway values that accordance to your network setup)
auto eth0
iface eth0 inet static
address 192.168.223.129
subnet 255.255.255.0
gateway 192.168.223.1
|
3. Save the file and close vi editor
4. Restart the network
# /etc/init.d/networking restart
|
5. Your server IP address will change to the static IP
6. Be cautious when you configure a static IP. It may cause IP conflict. Check the dhcp pool with your network administrator and use the IP that is not within the dhcp pool range. For example, if your DHCP pool is 192.168.1.100-192.168.1.200, you can set your static IP from 192.168.1.2-192.168.1.99 as well as 192.168.201-192.168.254. But you need to be sure that the IP you will using is not occupied by other servers or workstation.