Static IP Server Configure
In this post, we will see how we can set a static IP address on our Linux server, specifically an Ubuntu Server (Version > 17.10).
Ubuntu now uses Netplan
as the default network management tool to replace the old configuration file /etc/network/interfaces
that we can still find in other Linux Distributions.
Network Interface
First we need to find the network interface name that we are connected, we can do that with ifconfig
:
ifconfig
# ...
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.99 netmask 255.255.255.0 broadcast 192.168.1.255
We can also use the newer ip
command, if ifconfig
is not available:
ip a
# ...
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 50:46:5d:b5:82:f0 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.99/24 brd 192.168.1.255 scope global enp3s0
We can see that the network interface is enp3s0
and the IP address is 192.168.1.99
.
Netplan file
Netplan uses configuration files in YAML format. To configure a static local IP address with netplan
we need to edit the following yaml
file:
sudo vim /etc/netplan/01-netcfg.yaml
The 01-netcfg.yaml
file defore we change it will be like:
network:
version: 2
renderer: networkd
ethernets:
dhcp4: yes
And after the changes:
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
dhcp4: no
addresses:
- 192.168.1.99/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
We explain the additional field we added:
enp3s0
: The network interface namedhcp4: no
: We don’t want DHCP to give us an IP addressaddresses
: The IP address that we want to be assigned and the subnetgateway4
: The local networks gatewaynameservers
: The IP addresses of the nameservers we want to have
Give the file the proper permissions:
sudo chmod 600 /etc/netplan/01-netcfg.yaml
Apply changes:
sudo netplan apply
Verify the changes by typing:
ip addr show dev enp3s0
# ...
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 50:46:5d:b5:82:f0 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.99/24 brd 192.168.1.255 scope global enp3s0