Static IP on Ubuntu 17.10 and later

bash-script

 Show the network interfaces with the command ip link In the example below the interface is ens3

				
					sander@linuxsource:~$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff
				
			

The interface configuration files are stored in the /etc/netplan. There are multiple possibilities that depending on the your setup/OS. Edit one of the following files:
01-netcfg.yaml, 50-cloud-init.yaml, or NN_interfaceName.yaml

If it is an cloudinstance and provisioned with cloudinit, you have to disable it:

				
					sander@linuxsource:~$ sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

network: {config: disabled}
				
			

Assign the static ip address by editting the config file.  sudo nano /etc/netplan/01-netcfg.yaml
Change it from:

				
					network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes
				
			


to:

				
					network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      addresses:
        - 192.168.1.1/24
      gateway4: 192.168.1.254
      nameservers:
          addresses: [8.8.8.8, 8.8.4.4]
				
			

Press Control+X and save the file.
Then apply the changes with: sudo netplan apply

Then verify the changes with: 

				
					sander@linuxsource:~$ ip addr show dev ens3

2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global dynamic ens3
				
			
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

MAC recovery options

Next Post

CPU 100% in taskmanager not in processes

Related Posts