How to Configure Static IP Address in Ubuntu 18.04 / 16.04 / Debian 9 / LinuxMint 18
Abstract: # Static IP Address ## IP Address #
Setting up the network and bringing servers into the network is the initial administration task for any system administrator.
In some cases, these tasks are automated using DHCP (Dynamic Network Configuration Protocol) which takes care of assigning IP Address to Desktop and Servers.
READ: How to configure DHCP server on CentOS 7 / Ubuntu 18.04 / 16.04 / Debian 9
But, if you go to the bigger infrastructure they use static (manual) IP to avoid network problems due non-availability of DHCP servers.
Interested in Netplan – a new network tool for configuring networking on in Ubuntu 18.04 / Ubuntu 17.10.
READ: How To Configure Static IP Address in Ubuntu 18.04 using Netplan
Configure Static IP Address in Ubuntu / DebianLet us configure our network interface for the following information.
IP Address = 192.168.1.10
Netmask = 255.255.255.0
GATEWAY=192.168.1.1
DNS Server 1 = 192.168.1.1
DNS Server 2 = 8.8.8.8
Domain Name = itzgeek.local
Switch to the root user.
su -
OR
sudo su -
Make sure you install ifupdown and resolvconf package.
apt-get -y install ifupdown resolvconfFind the available network interfaces on your system
You can use any one of the below commands to get a list of network interfaces available on your system.
ifconfig
OR
ip aChoose the desired network interface
The output of the ifconfig command:
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.6 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fd50:1d9:9fe3:1400:79fa:c48f:b679:c85 prefixlen 64 scopeid 0x0 inet6 fd50:1d9:9fe3:1400:a00:27ff:fe36:34ae prefixlen 64 scopeid 0x0 inet6 fe80::a00:27ff:fe36:34ae prefixlen 64 scopeid 0x20 ether 08:00:27:36:34:ae txqueuelen 1000 (Ethernet) RX packets 226971 bytes 327928478 (312.7 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 60417 bytes 4869126 (4.6 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback) RX packets 4714 bytes 6158753 (5.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4714 bytes 6158753 (5.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
At this time, my system interface (enp0s3) takes IP Address from DHCP server.
READ: How to configure DHCP server on CentOS 7 / Ubuntu 18.04 / 16.04 / Debian 9
For this demo, we will configure a static IP for that interface.
Configure Static IP AddressEdit the interfaces file.
nano /etc/network/interfaces
Update the file with below information. If you are adding DNS entries in /etc/network/interfaces file, then you need to install the resolvconf package
# Interface Name # auto enp0s3 # Static IP Address # iface enp0s3 inet static # IP Address # address 192.168.1.10 # Netmask # netmask 255.255.255.0 # Gateway # gateway 192.168.1.1 # DNS Servers # dns-nameservers 192.168.1.1 dns-nameservers 8.8.8.8 # Search Domain # dns-search itzgeek.local
Restart the networking using the following command.
service networking restartVerify Static IP Address
Verify the static IP using below commands.
ifconfig
OR
ip a
Output:
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fd50:1d9:9fe3:1400:a00:27ff:fe36:34ae prefixlen 64 scopeid 0x0 inet6 fe80::a00:27ff:fe36:34ae prefixlen 64 scopeid 0x20 ether 08:00:27:36:34:ae txqueuelen 1000 (Ethernet) RX packets 107 bytes 10918 (10.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 165 bytes 22379 (21.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback) RX packets 824 bytes 66440 (64.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 824 bytes 66440 (64.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Also, verify the DNS servers entries.
cat /etc/resolv.conf
Output:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 192.168.1.1 nameserver 8.8.8.8 search itzgeek.local
That’s All.