Most of operating systems provides commands or options to setup network interface using 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.
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 localhoststation1.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 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. Configure IP Address 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 Virtual IP on Interface
Now if you want to add second ip address (virtual ip) on same interface (eth1). You can define alias in network configuration file and configure another ip address.
$ sudo vi /etc/network/interfaces
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
5. Restart Network Service
After making all above changes just restart network service using following command.
$ sudo /etc/init.d/networking restart
Nice information, This helped me out of a jam.
Keep up the good work.
Thanks
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.