How to Manage Your IP Address on Linux: Finding, Setting, and Changing
Whatsapp Pinterest
Advertisement

The IP address is like your computers phone number What Is a Static IP Address, How Do I Get One & Its Advantages/Disadvantages What Is a Static IP Address, How Do I Get One & Its Advantages/Disadvantages In home networks, IP addresses aren't usually fixed, but they do fall within specific ranges. A static IP address doesn't change. What are the advantages to this, and why would you want one? Read More . Your computer uses it to contact other devices and vice versa. Here are some of the easiest ways to manage your Linux IP address.

How to Find Your IP Address and DNS Address

Using the Command Line

The old method for doing this was using the ifconfig command. However, that has since been replaced with the ip command. To show your IP address type:

ip addr show

how to manage your ip address in linux

In amongst the alphabet soup that is returned is a single line showing your IP address in Classless Inter-Domain Routing (CIDR) notation. This basically shows your IP address along with your subnet mask. If you see dynamic, then your IP address has been automatically assigned using DHCP.

The output also displays information for any network devices or interfaces installed on your system as devices such as laptops may have both wired and wireless ethernet. The most common interface name is eth0, but in Ubuntu Systems with systemd (like Ubuntu 16.04 and newer), the network interface is named ens33.

To get the DNS addresses associated with an interface type the following:

nmcli device show <interface> | grep IP4.DNS

how to manage your ip address in linux

Using the GUI

Showing your IP address in the GUI is also quite simple. On older systems click on Connection Information under the networking icon from the top bar. The IP address, primary and DNS servers will all be displayed in the Connection Information window.

how to manage your ip address in linux

In newer versions of Ubuntu, there are a few more clicks involved. Under the same networking icon on the top bar select settings from the interface that’s connected. Click on the gear icon and view your IP address from the window that pops up.

how to manage your ip address in linux

How to Set or Change IP Address (on Older Systems)

Using the Command Line

Older desktop versions of Ubuntu use the etc/network/interfaces file. Display the contents of the file using the cat command and if the contents look like the picture below your system is using an older version of the networking service.

how to manage your ip address in linux

Currently, your system is configured to get its IP address automatically using DHCP. To make changes open the interfaces file using nano and set the values in the file as necessary. First change dhcp to static, then add lines for address, netmask, gateway, and DNS servers according to your network.

sudo nano /etc/network/interfaces

how to manage your ip address in linux

After you’ve made your changes close the file by pressing Ctrl + X and save the changes. Finally, restart the networking service using the following command for your changes to take effect.

sudo /etc/init.d/networking restart

Using the GUI

To configure your IP address in older Ubuntu systems, navigate to System Settings > Network > select the interface you would like to configure and click the Options button. Click on the IPv4 tab, select Manual from the Method drop-down list, and finally select the Add button.

how to manage your ip address in linux

Set your Address, Netmask, Gateway, and DNS servers according to your network. Finally, click Save to accept the changes for your new network configuration.

How to Set or Change IP Address (on Newer Systems)

Using the Command Line

The network configuration has been changed completely with Ubuntu 17.10 with a new tool called Netplan. The Netplan configuration files are located in /etc/netplan and just like the older method you can configure your networking with a text editor.

Netplan uses a syntax which is similar to JSON What Is JSON? A Layman's Overview What Is JSON? A Layman's Overview Whether you plan to be a web developer or not, it's a good idea to at least know what is JSON, why it's important, and why it's used all around the web. Read More namely Yet Another Markup Language (YAML). YAML is quite polarizing, and many developers either love it or hate it. One of the reasons is because YAML takes into account the indentation or the lines so be extra cautious with that space bar.

To make changes to your networking open the file located in /etc/netplan/ to make the necessary changes:

sudo nano /etc/netplan/01-network-manager-all.yaml

To set your IP address statically set the values in the file according to your network. Here is an example of the file which sets the IP, gateway, and DNS addresses:

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.100/24]
  gateway4: 192.168.1.1
  nameservers:
addresses: [8.8.8.8,8.8.4.4]

If you would prefer to go back to get an IP address assigned automatically through DHCP set the file as follows:

This file describes the network interfaces available on your system
For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
ens33:
  dhcp4: yes
  dhcp6: yes

Run the following command to apply the changes, or run it with the optional debug switch to get some useful output to ensure your file was parsed correctly:

sudo netplan apply
sudo netplay --debug apply

Using the GUI

To set the IP address in the GUI, go to Settings > Network and click on the gear icon of the interface you would like to configure. Click on the IPv4 tab, select Manual and enter your settings as required. Click Apply to accept your changes and enjoy your new network settings.

how to manage your ip address in linux

How to Set or Change Your Hostname

Using the Command Line

Just like your IP address, your computer is also addressable by its device name or hostname. Similar to your IP address, no two devices can have the same hostname on your network, and it can also be changed with just a text editor. To set your hostname type:

sudo nano /etc/hostname

how to manage your ip address in linux

Click Ctrl + X to exit and don’t forget to save changes. The last file you need to edit is the /etc/hosts file. Under the line which has localhost is the line which displays your old hostname. Change the old hostname to your new desired hostname and click Ctrl + X to exit and save your changes. The final step will be to restart your device using the reboot command for the changes to take effect.

how to manage your ip address in linux

The hosts file is used to map hostnames to IP addresses and is common to almost all operating systems. For example, if you were to ping localhost from the terminal, it would resolve to 127.0.0.1 because of the first line in the hosts file. This is the reason we need to update it with the new hostname to ensure it gets resolved correctly.

Using the GUI

While you can change your hostname from the GUI, you will still need to edit the hosts file from the terminal after making the edit in the GUI. To change your hostname navigate to Settings > Details > About, change the Device name and close the window. Now change the hosts file as detailed above and reboot your system for changes to take effect.

how to manage your ip address in linux

More Ways to Manage Your Network on Linux

Viewing or making changes to your IP and network settings is really straightforward. There are also some other networking commands 5 Networking Commands for the Linux Terminal 5 Networking Commands for the Linux Terminal You can get a lot done in the command line in Linux, including managing and troubleshooting network issues. Find out about the new ip command, wget, ping, and more. Read More that you can run from the terminal to master your command line game.

Explore more about: IP Address, Linux Commands, Troubleshooting.

Enjoyed this article? Stay informed by joining our newsletter!

Enter your Email

Leave a Reply

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

  1. dragonmouth
    June 4, 2018 at 7:31 pm

    The title should be "How to Manage Your IP Address on UBUNTU...." since the entire article is only about Ubuntu. Ubuntu may arguably be the most popular Linux distro, but it is not the only one. Large majority of Linux users use distros that are not Ubuntu-based.

    If the author wants to write, or is assigned, an article about a particular distros, great. But do not make it sound like the article applies to ALL Linux distros.

    • Jim
      June 6, 2018 at 10:47 am

      I do agree this article focuses on Ubuntu, but making any article about "all LInux distros" is darn near impossible, considering how many and Linux distros exist!

      • dragonmouth
        June 6, 2018 at 1:30 pm

        No need for an article about "all Linux distros". If the article is about a specific distro, say so in the title. AFAIAC, this article is nothing more than click bait. I use PCLinuxOS. With the exception of a couple of bash commands, all the examples provided are useless to me, as well as to all other non-Ubuntu users.

        My problem with this article, or its title, and most other articles about Linux is that the writers are trying to cram Ubuntu down the users throats by making it sound like Linux IS Ubuntu.