Configure Network in Debian / Ubuntu / LinuxMint
After the installation of Ubuntu / Debian, you must configure the network to access your system from outside. This guide helps you to set network in Ubuntu / Linux Mint. Here I will show you assigning ipaddress in Static and in DHCP mode.
Note: This should also work on previous versions of Ubuntu such as Ubuntu 13.10 / 13.04 / 12.10 and LinuxMint 17 / 16.
Static Mode
In this mode, we will manually assign an IP address to machines. Let’s check the available interfaces on our system.
[email protected]:~$ ip a 1: lo: <loopback,up,lower_up> 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: <broadcast,multicast> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:0c:29:55:f6:b8 brd ff:ff:ff:ff:ff:ff
From the above output, you can see my system has two interfaces namely “lo” and “eth0“. Depends on hardware, the name of the interface will change.
Now, we will set ipaddress to an interface “eth0“. To do that, add the “static” method to the set address family statement for the “eth0” interface in the file /etc/network/interfaces. Change the address, netmask, and gateway values to meet the requirements of your network.
[email protected]:~$ sudo nano /etc/network/interfaces
Just modify the lines like this.
auto eth0 iface eth0 inet static ## Static IP Address Enabled address 192.168.12.10 ## IP Address netmask 255.255.255.0 ## Subnet Mask gateway 192.168.12.2 ## Default Gateway dns-nameservers 8.8.8.8 8.8.4.4 ## DNS Servers dns-search itzgeek.local ## Local Domain Search - Ignore if not required
By adding an interface configuration, as shown above, you can manually enable the interface through the ifup command.
[email protected]:~$ sudo ifup eth0
To manually disable the interface, you can use the ifdown command.
[email protected]:~$ sudo ifdown eth0
Now you can see the ip address “192.168.12.10” assigned to the interface “eth0“.
[email protected]:~$ ip a 1: lo: <loopback,up,lower_up> 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: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:55:f6:b8 brd ff:ff:ff:ff:ff:ff inet 192.168.12.10/24 brd 192.168.12.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe55:f6b8/64 scope link valid_lft forever preferred_lft forever
DHCP Mode
In this mode, the system will get an IP address from DHCP servers. Let’s check the available interfaces on your system.
[email protected]:~$ ip a 1: lo: <loopback,up,lower_up> 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: <broadcast,multicast> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:0c:29:55:f6:b8 brd ff:ff:ff:ff:ff:ff
From the above output, you can see my system has two interfaces namely “lo” and “eth0“. Depends on hardware, the name of the interface will change.
Now, we will set ipaddress to an interface “eth0“. To do that, add the “dhcp” method to the inet address family statement for the “eth0” interface in the file /etc/network/interfaces. Change the address, netmask, and gateway values to meet the requirements of your network.
[email protected]:~$ sudo nano /etc/network/interfaces
Just modify the lines like this.
auto eth0
iface eth0 inet dhcp ## Enabled DHCP Mode
By adding an interface configuration, as shown above, you can manually enable the interface through the ifup command.
[email protected]:~$ sudo ifup eth0
To manually disable the interface, you can use the ifdown command.
[email protected]:~$ sudo ifdown eth0
Now you can see the ip address “192.168.12.3” assigned to the interface “eth0” using DHCP.
[email protected]:~$ ip a 1: lo: <loopback,up,lower_up> 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: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:55:f6:b8 brd ff:ff:ff:ff:ff:ff inet 192.168.12.3/24 brd 192.168.12.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe55:f6b8/64 scope link valid_lft forever preferred_lft forever
That’s All.