I will warn you in advance that the setup of a static IP address on a Linux Ubuntu server will vary greatly depending on which version of the operating system you are using and how the version came to be. An Ubuntu installation that started life as Ubuntu 12 and has been upgraded every 2 years is going to have a different IP address configuration process compared to a new installation or even an installation of Ubuntu 18 followed by an upgrade!
The tutorial presented in the video and described here is based on a “clean install” of the Ubuntu Server 20.04 live ISO. I will add additional posts for other versions as I get the time but initially I am providing only Ubuntu 20.
Prerequisites
- Working Ubuntu 20 and a user account that is in the sudo group.
- Basic file editing (nano, vi, etc)
Netplan
In Ubuntu 20.04 the IP address configuration is based on “netplan” which is a package where you write your IP address configuration in a language called YAML (luckily you do not actually need to go and read this).
What is Your Ethernet Device?
Before beginning you need to know the name of the network interface on your machine which normally will be of the form ethN or enpNsN (where N is a number).
On Ubuntu, you can use the “ip addr” to list the interfaces. You can also search the kernel ring buffer for the device
Sample 1:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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 mq state UP group default qlen 1000 link/ether 00:15:5d:64:13:2b brd ff:ff:ff:ff:ff:ff inet 192.168.68.12/24 brd 192.168.68.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::215:5dff:fe64:132b/64 scope link valid_lft forever preferred_lft forever
In this example, there is a single device called “eth0”.
Sample 2:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 70:e1:4c:68:38:86 brd ff:ff:ff:ff:ff:ff inet 192.168.100.9/24 brd 192.168.100.255 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::72e1:4cff:fe68:3886/64 scope link valid_lft forever preferred_lft forever 3: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 70:e1:4c:68:38:87 brd ff:ff:ff:ff:ff:ff inet 192.168.68.1/24 brd 192.168.68.255 scope global enp2s0 valid_lft forever preferred_lft forever inet6 fe80::72e1:4cff:fe68:3887/64 scope link valid_lft forever preferred_lft forever 4: wlp3s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 8c:70:5a:95:a5:20 brd ff:ff:ff:ff:ff:ff
This particular example is more complex since there are two wired interfaces and one wireless. The two wired interfaces are called enp1s0 and enp2s0. If you search the kernel ring buffer (using “dmesg | grep eth”) you get the following details:
robert@gate:~$ dmesg | grep eth [ 1.930793] r8169 0000:01:00.0 eth0: RTL8168evl/8111evl at 0xffffc9000075a000, 70:e1:4c:68:38:86, XID 0c900800 IRQ 89 [ 1.930796] r8169 0000:01:00.0 eth0: jumbo features [frames: 9200 bytes, tx checksumming: ko] [ 1.931566] r8169 0000:02:00.0 eth1: RTL8168evl/8111evl at 0xffffc9000075c000, 70:e1:4c:68:38:87, XID 0c900800 IRQ 90 [ 1.931569] r8169 0000:02:00.0 eth1: jumbo features [frames: 9200 bytes, tx checksumming: ko] [ 2.021611] r8169 0000:02:00.0 enp2s0: renamed from eth1 [ 2.036777] r8169 0000:01:00.0 enp1s0: renamed from eth0
From the kernel buffer we see that eth0 and eth1 are first detected but then renamed to enp1s0 and enp2s0. This renaming of the interfaces was found in Ubuntu 16, but it seems to have gone away since Ubuntu 18. If you are working on a server that started life as Ubuntu 16 and somebody ran an upgrade to Ubuntu 18 or Ubuntu 20, you can expect these “enp” renaming.
Configuration File
The main configuration file is located at /etc/netplan/00-installer-config.yaml. You can edit this with any text editor (the video demonstrates using the nano editor).
Default File
The initial file created by the installation is set up to pick up an IP address from the DHCP server on the local area network.
network: ethernets: eth0: dhcp4: true version: 2
IPv4 Configuration
Below sets the eth0 device to have IP addresses 192.168.68.12 and 192.168.68.13 with subnet mask 255.255.255.0. You of course can set just a single value but I will be using the multiple IP addresses later in the Apache2 configuration section.
network: ethernets: eth0: dhcp4: false addresses: [192.168.68.12/24, 192.168.68.13/24] gateway4: 192.168.68.1 nameservers: addresses: [192.168.68.1] version: 2
IPv6 Configuration
My ISP doesn’t currently provide any IPv6 support so I don’t have any ready made examples but I’ve added a place holder to my road map to remind myself that I need to write a tutorial.
Apply the Configuration
Once the configuration file has been saved, you can use the command: “netplan apply” to set the ip address.
Once set, use the “ip addr” to verify the settings.
root@wsmdemo:/etc/netplan# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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 mq state UP group default qlen 1000 link/ether 00:15:5d:64:13:2b brd ff:ff:ff:ff:ff:ff inet 192.168.68.12/24 brd 192.168.68.255 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.68.13/24 brd 192.168.68.255 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::215:5dff:fe64:132b/64 scope link valid_lft forever preferred_lft forever
Of course you should also try pinging these ip addresses from another computer on your network and try connecting using ssh to your server.
Other Ubuntu Versions?
Do you have another version of Ubuntu besides 20? Check the roadmap page and see if I have created a page for setting the static IP address. I will eventually write one page for everything.
New Install Ubuntu 20.04 Server or static ip change. Will seach elsewhere for fixed static.
ubuntu@ubuntu:~$ ifconfig
eth0: flags=4163 mtu 1500
inet 192.168.42.19 netmask 255.255.255.0 broadcast 192.168.42.255
inet6 fe80::dea6:32ff:fe62:f856 prefixlen 64 scopeid 0x20
inet6 2001:5b0:2866:e7e8:dea6:32ff:fe62:f856 prefixlen 64 scopeid 0x0
ether dc:a6:32:62:f8:56 txqueuelen 1000 (Ethernet)
RX packets 112674 bytes 157806524 (157.8 MB)
RX errors 0 dropped 740 overruns 0 frame 0
TX packets 23562 bytes 1843258 (1.8 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 204 bytes 17466 (17.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 204 bytes 17466 (17.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ubuntu@ubuntu:~$ sudo nano /etc/netplan/*.yaml
ubuntu@ubuntu:~$ 00-installer-config.yaml
00-installer-config.yaml: command not found
o response necssary.
Seems that my email notifications are not working well…sorry for the slow answer.
To apply the configuration you need to use the command “netplan apply”.