I'm looking for the correct way of configuring the network with static IP on Ubuntu Desktop 18.04, but from the command line and not the GUI.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
I think this is as close to the "correct way" as you can get.
First you must find out what your interface name is. To do that just run
ip address from the Terminal. On my machine it is
eno1 which can be found on the first line:
me@pc:~$ ip address 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 90:b1:1c:aa:bb:cc brd ff:ff:ff:ff:ff:ff inet 10.1.2.16/24 brd 10.1.2.255 scope global eno1 valid_lft forever preferred_lft forever inet6 fe80::5cd1:3ee8:c461:6f12/64 scope link noprefixroute valid_lft forever preferred_lft forever
Then you just need to edit the file
/etc/netplan/01-network-manager-all.yaml and make it look like this for a static IP address assignment:
# Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager ethernets: eno1: renderer: networkd match: name: eno1 addresses: [10.1.2.16/24] gateway4: 10.1.2.1 nameservers: search: [example.com] addresses: [10.1.2.10]
This tells netplan to use networkd on the interface
eno1 instead of NetworkManager.
For wifi to work properly below, make sure you replace
wlan0 with your exact wifi name.
You can use systemd directly by adding config files to /etc/systemd/network/*.network
[Match] Name=eth0 [Network] Address=10.10.10.9/24 Gateway=10.10.10.1 DNS=220.127.116.11
[Match] Name=wlan0 SSID=Wifi-SSID [Network] DHCP=ipv4
I don't use netplan, so I prefer to remove it:
apt purge netplan.io rm -rf /etc/netplan
systemctl unmask systemd-networkd systemctl enable systemd-networkd
Set Wifi password and start at boot:
wpa_passphrase Wifi-SSID Sweet-Password >> /etc/wpa_supplicant/wpa_supplicant-wlan0.conf systemctl enable email@example.com
Speed up boot times by refusing to wait for network at boot:
systemctl disable systemd-networkd-wait-online.service
I can see this is old, but I've added a different method here, which doesn't use a layer of abstraction, such as netplan.io or NetworkManager, which probably more closely answers the title of this thread, if not the question.
Personally, I prefer this method because:
Seriously, take a look at the Arch wiki page which explains it in excellent detail with examples. Read the whole thing, because there are a few gotchas. https://wiki.archlinux.org/index.php/Systemd-networkd