How to Setup Network Interface Card in Ubuntu

Next, I will show how to setup a basic network configuration inside Ubuntu. The first thing you need to do is to boot up your Ubuntu and log into the root account. If your Ubuntu forbids direct login to root, then just login using a normal user:

You may type ifconfig to display your current network configuration:



From the above picture, you can see that:
1)      eth0 – is your first network interface card inside your server
2)      lo – the loopback interface to access your local services such as proxy or webserver http://127.0.0.1

The network card settings can be found edit here:
sudo vi /etc/network/interfaces

SETUP STATIC IP

You may type like below inside your interface configuration file:
auto eth0
iface eth0 inet static
address 192.168.1.38
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255

Please take note that only address and netmask is required to be inserted into the configuration. The gateway, network, and broadcast are optional. You may enter it or Ubuntu will automatically calculate the other three based on your address and netmask.

You may type this if you want to read more about the network settings help provided inside Ubuntu:
man interfaces

SETUP DHCP

In order to setup DHCP for the network interface card, just type like below inside the /etc/network/interfaces file:
auto eth0
iface eth0 inet dhcp

CONFIGURE DNS

Next is to configure the DNS in order for it to resolve your domain name request into IP for the server to understand it. To configure, type:
sudo vi /etc/resolv.conf

Then you may add any DNS you want inside the file:
nameserver 8.8.8.8
nameserver 202.188.245.2
nameserver 202.188.0.133

RESTART THE NETWORK SERVICE

After finished editing any of the network setting, you need to restart the network service in order for new changes to take effect. To restart, type:
sudo /etc/init.d/networking restart

You may type ifconfig to see your new network settings:

You also may test ping a domain name to see whether your network settings is working or not by typing:
ping google.com

If you got the reply, this means your setup was successful.

ASSIGN MULTIPLE IP IN NETWORK INTERFACE CARD

The procedure would be the same like adding normal IP address to the network interface card. Just open up the network interface card settings by typing:
sudo vi /etc/network/interfaces

Then add these following lines (depending on how much additional IP you want to add):
auto eth0 eth0:1 eth0:2
iface eth0 inet static
address 192.168.1.38
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255
iface eth0:1 inet static
address 192.168.1.40
netmask 255.255.255.0
iface eth0:2 inet static
address 192.168.1.41
netmask 255.255.255.0

After saving and restarting the network, you can check your new setting by typing ifconfig


Leave a Reply