Skip to content

Instantly share code, notes, and snippets.

@infamousjoeg
Last active July 20, 2018 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infamousjoeg/9b451d895fa8b5f3e4b1bef631b4a351 to your computer and use it in GitHub Desktop.
Save infamousjoeg/9b451d895fa8b5f3e4b1bef631b4a351 to your computer and use it in GitHub Desktop.
Networking in Ubuntu 18.04 - Setting a Static IP

Configuring Static IP Addresses With Networkd

To configure a static IP address using the new NetPlan tool, the file should look like this: IPv4 address (192.168.1.2), Gateway (192.168.1.1), DNS Servers (8.8.8.8,8.8.4.4)

Run the commands below to create a new network configuration file

sudo nano /etc/netplan/01-netcfg.yaml

Then configure IPv4 addresses as shown below… take notes of the format the lines are written…

This file describes the network interfaces available on your system

For more information, see netplan(5).

network:
 version: 2
 renderer: networkd
 ethernets:
   ens33:
     dhcp4: no
     dhcp6: no
     addresses: [192.168.1.2/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]

Exit and save your changes by running the commands below

sudo netplan apply

You can add IPv6 addresses line, separated by a comma.. example below.

This file describes the network interfaces available on your system

For more information, see netplan(5).

network:
 version: 2
 renderer: networkd
 ethernets:
   ens33:
     dhcp4: no
     dhcp6: no
     addresses: [192.168.1.2/24, '2001:1::2/64']
     gateway4: 192.168.1.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]

Save your changes, apply and you’re done.

This is how to set static IP addresses on Ubuntu 18.04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment