We often need to configure IP (static or dynamic), especially on newly installed Ubuntu. However, since we have not systematically summarized this, this makes our memory always a little confused, but it’s actually very simple.

Here’s how to get networking all the way up in a matter of seconds using just a few commands from the terminal.


There are two ways to do this:

  • Using ifconfig (DEPRECATED)
  • Using ip and netplan (RECOMMEND)

And we also need to find out our network interface:

Identify Ethernet Interfaces

To quickly identify all available Ethernet interfaces, you can use the ip command as shown below.

$ ip link


ip a

Using ifconfig

Configure Dynamic IP:

# Reset IP Address
$ ifconfig eth0

# Start DHCP
$ dhclient

Configure Static IP:

# Stop DHCP
$ killall dhclient

# Set Your IP Address
$ ifconfig eth0 netmask up

# Set Your Default Gateway
$ route add default gw

# Set Your DNS Server
$ echo "nameserver" > /etc/resolv.conf

Using ip and netplan

Since ifconfig is being phased out, it’s time to get used to the new system. By default, some Linux distribution (e.g. Ubuntu 18.04) doesn’t use ifconfig anymore, and instead uses the new commands, ip and netplan.

Firstly we need to configure network interface:

# Show your IP
$ ip addr show

# Bring an interface up or down
$ ip link set eth0 up/down

# Showing your routing
$ ip route show

# Show your DNS servers
$ systemd-resolve --status

# Show your network status
$ networkctl -a status

And then we edit our networking plan:

For Ubuntu, here’s the replacement for editing /etc/networking/* in the old system. The whole system now uses YAML configuration files under /etc/netplan.

$ vi /etc/netplan/99_config.yaml

Netplan configuration as below:

  renderer: networkd
      addresses: [] # for static IP
      dhcp4: true # for dynamic IP
      optional: true
        addresses: [,]
  version: 2

And then to apply the configuration, run command as below:

$ netplan apply

Checking Network Connectivity

Assuming you have configured your network, now it’s time for us to check if you’re all set. Test by ping any domain name:

$ ping


If you’re using an older Linux system, the ifconfig way you have to do. If you’re on a newer system, never forget to use the new way ip and netplan, it’s really recommended for you.