Back

Configuring IP Addresses in Ubuntu: Quick Reference

Networking in Ubuntu has always been frustrating and inconsistent for me. Hope this helps you as much as it helps me.

Written by Allen Liu, Self-published 2025 - 06 - 22

1. Quick Reference: /etc/NetPlan/00-installer-config.yaml

#### This file commonly shows up as '00-installer-config.yaml' #### but it may also show up starting with a '50' or something #### else. If no such file exists, try a different configuration #### file. #### NOTE: Because YAML is YAML, indentation must be spaces and #### must be precise. network: ethernets: eth0: addresses: - 10.2.3.4/24 nameservers: addresses: [10.2.3.2,8.8.8.8] routes: - to: default via: 10.2.3.1 # DHCP Example eth1: dhcp4: true version: 2 #### Apply your configuration using 'sudo netplan apply'.

2. Quick Reference: /etc/network/interfaces:

iface eth0 inet static address 10.2.3.4/24 gateway 10.2.3.1 nameserver 10.2.3.2 8.8.8.8 #### DHCP Example iface eth1 inet dhcp # Apply configuration using 'sudo /etc/network/interfaces.d restart'.

3. Quick Reference: ip

#### Note: I don't recommend using ip. See The Words for more. sudo ip address set dev eth0 address 10.2.3.4/24 sudo ip route add default via 10.2.3.1 sudo ip route add 0.0.0.0/0 via 10.2.3.2 #### Cannot configure DNS server using IP. Instead, configure #### DNS servers by modifying /etc/resolv.conf and adding #### these lines: #### #### nameserver 10.2.3.2 #### nameserver 8.8.8.8 #### ip command cannot be used to configure dhcp. Use #### dhclient instead: sudo dhclient eth1

4. The Words

Configuring networking in Ubuntu has always been a pain. But using these three methods plus using the GUI should help network any fresh Ubuntu machine without using a GUI.

4.1. Netplan

Netplan is one of the newer methods. Netplan uses YAML notation meaning that it is very picky about formatting. You may simply copy paste the example and write in your desired addresses.

Using netplan, you are able to configure the IP address, DNS server, and default route. The basic structure is as follows:

network: ethernets: <interface name>: dhcp4: true/false addresses: - x.x.x.x/x nameservers: addresses: [x.x.x.x,y.y.y.y] routes: - to: default via: x.x.x.x # etc... version: 2

Note that the 'dhcp4' field decides whether to use DHCP or not. If set to 'true', i.e. you want to use DHCP, you may omit the other lines. If set to 'false', you may omit the 'dhcp4' line and instead just put the IP address. Both of these examples are provided in the Quick Reference.

Also note that the version field cannot be ommitted. Because of the way the file works, it needs to know which version of the file to look for. Without this field, netplan will not be able to interpret the file properly.

You can commit your config with a full reboot or by running sudo netplan apply.

4.2. /etc/network/interfaces

/etc/network/interfaces is one of the older methods of configuring IP addressing. The formatting is not precise and only requires white space. In fact, if you wanted, you could collapse each interface into their own line, but we're not doing that here. The basic structure is as follows:

iface <interface name> inet static/auto address x.x.x.x/x gateway x.x.x.x nameserver x.x.x.x y.y.y.y # etc...

`iface` denotes an interface description, the name denotes the name of the interface, and inet denotes an IPv4 address. I do want to write an article about how to do this with IPv6 in the future, but for now, just stick to IPv4. Using `static` denotes a statically defined address, and `auto` denotes a DHCP address.

This config can be committed by rebooting or using `sudo /etc/network/interfaces.d restart`.

4.3. ip

The `ip` command replaced the older `ifconfig` for a lot of things, and it includes the ability to set temporary IP addresses, as well as overload a single interface with multiple IP addresses. The biggest problem with IP though is that these interfaces are temporary; they do not survive a reboot. To commit a new IP address permanently, use one of the other two methods presented previously.

The `ip` command is a pain to look through the documentation for, but I will flag only three main comamnds to know here.

sudo ip address add/set/del dev <interface name> address x.x.x.x/x sudo ip route add x.x.x.x/x via x.x.x.x

As you might expect, these commands configure an IP address and an IP route respectively. The `ip route` command can be used to, for example, configure a default gateway, such as in the quick reference example. The `ip address` command can be used to manage an interface's IP address, including setting an IP address, adding multiple IP addresses, or deleting IP addresses. To overload an interface with multiple IP addresses, you can do something like the following:

sudo ip address add dev eth0 address 10.1.1.1/24 sudo ip address add dev eth0 address 10.2.2.2/24

However, there's very little reason to do this. Because of the way the `ip` command works, however, you may find that you have accidentally configured multiple IP addresses on an interface, as shown below. Simply delete the old IP address.

$ ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 127.0.0.2/8 scope host secondary lo valid_lft forever preferred_lft forever # etc... $ sudo ip address del dev lo address 127.0.0.1/8 $ ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever # etc...

As noted in the quick reference, you cannot configure DNS or DHCP using the `ip` command. Instead, you may perform a DHCP request using `dhclient <interface name>`. This will allow your interface to grab a DHCP address from a server, but you will have to rerun it everytime you want a new lease.

DNS servers can be configured using `/etc/resolv.conf`. Simply add the IP addresses preceeded by `nameserver`. If your file tells you not to edit the file, you should first delete the file, then make a new file. An example file is provided below.

nameserver 10.2.3.2 nameserver 8.8.8.8

Like the rest of the commands in this section, this is a live change, so no commit is needed. Unlike the rest of the commands in this section, this will survive a reboot.

5. References I looked at while making this

  1. About Netplan- Ubuntu Documentation. Last updated 2025 - 06 - 19. Contributed by Charles Uneze. Accessed 2025 - 06 - 21. Link: https://documentation.ubuntu.com/server/explanation/networking/about-netplan/.
  2. Configuring networks- Ubuntu Documentation. Last updated 2025 - 06 - 19. Contributed by Charles Uneze. Accessed 2025 - 06 - 21. Link: https://documentation.ubuntu.com/server/explanation/networking/configuring-networks/
  3. Setting a Static IP Address on Ubuntu Server 24.04/22.04 LTS- gal.vin. Dated 2023 - 01 - 26. Accessed 2025 - 05 - 23. Link: https://gal.vin/posts/2023/ubuntu-static-ip/.
  4. ip route add network command for Linux explained- cyberciti.biz. Last updated 2024 - 06 - 28. Authored by Vivek Gite. Accessed 2025 - 06 - 21. Link: https://www.cyberciti.biz/faq/ip-route-add-network-command-for-linux-explained/.
  5. Changes in /etc/network/interfaces do not make any changehttps://askubuntu.com/questions/194029/changes-in-etc-network-interfaces-do-not-make-any-change.
  6. What is the difference between "00-installer-config.yaml" and "50-cloud-init.yaml"- askubuntu. Asked 2020 - 07 - 21 by ProTofik. First answer posted 2020 - 11 - 27 by James Smith, accepted answer posted 2022 - 10 - 19 by black_hat_cat. Accessed 2025 - 05 - 23. Link: https://askubuntu.com/questions/1260951/what-is-the-difference-between-00-installer-config-yaml-and-50-cloud-init-yam.
  7. How do I set a static IP in Ubuntu?- askubuntu. Asked 2016 - 05 - 01 by TeeStart. Accepted answer posted 2016 - 05 - 04 by lewis4u. Accessed 2025 - 05 - 23. Link: https://askubuntu.com/questions/766131/how-do-i-set-a-static-ip-in-ubuntu.
  8. temporarily set eth0 to dhcp linux- serverfault. Posted 2022 - 12 - 07 by Jonathan Leslie, answer posted 2022 - 12 - 08 by Jasen. Accessed 2025 - 06 - 21. Link: https://serverfault.com/questions/1117511/temporarily-set-eth0-to-dhcp-linux.
  9. use dhcp on eth0 using command line- Unix & Linux Stack Exchange, Posted 2016 - 10 - 19 by user197699, accepted answer posted 2016 - 10 - 29 by andreatsh. Accessed 2025 - 06 - 21. Link: https://unix.stackexchange.com/questions/319740/use-dhcp-on-eth0-using-command-line.
HTML/CSS References