Most operating systems provide commands or options to setup network interface using the command line. On Linux systems, we can directly edit network configuration files and make changes as per our requirements. This tutorial will help you to How to Setup Network Interface on Ubuntu, Debian, and LinuxMint systems.

Advertisement

1. Setup System Hostname

You can use ‘hostname‘ command to check current set hostname or to set new hostname of system.

  • Type hostname on command prompt and press enter to check current hostname of system.
    hostname
    
  • Type new hostname with hostname command to set it. This will not persist after system reboot.
    hostname station1.example.com
    

To set hostname permanently, you need to edit /etc/hostname file and add new hostname. This will remain even after system reboot.

sudo echo "station1.example.com" > /etc/hostname

Now edit /etc/hosts and bind new hostname with local ip address.

127.0.0.1 localhost station1.example.com

2. List Attached Network Interfaces

To view or list attached network interfaces on system use following command. This will also show the state of the network interface.

ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:27:0e:1d:62:ab brd ff:ff:ff:ff:ff:ff
3: eth1:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:e0:4d:77:8a:0e brd ff:ff:ff:ff:ff:ff

3. Setup Static IP on Interface

Now edit your network interface configuration file /etc/network/interfaces and configure it. For the example, we are configuring eth0 interface to get ip address from DHCP server and eth1 will have a static ip address.

$ sudo vi /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8

4. Setup Second IP on Network Interface

Now if you want to add second IP address (Virtual IP) on the same interface (eth1). You can define an alias in network configuration file and configure another IP address.

sudo vi /etc/network/interfaces
## other configuration goes here 

auto eth1:0
iface eth1:0 inet static
address 192.168.1.101
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8

You can see here we have defined an interface as eth1:0, which is an alias of the interface.

5. Restart Network Service

After making all above changes just restart network service using following command.

eth1:0sudo /etc/init.d/networking restart
Share.

2 Comments

  1. Charles Kemp on

    Thank you for the help on setting up a network service interface on these different systems. I think in order to really know how to set up a network properly you should know the operating system. It would be hard to do anything without that kind of help.

Exit mobile version