- 3 ways to configure a network interface in Linux
- Great Linux resources
- At installation time
- How to Configure Network Settings in Ubuntu
- Setting/Changing an IP address
- Method #1: Network configuration on the command line
- Method #2: Network configuration using the GUI
- Method #3: Configure the network by editing /etc/interfaces file
- Setting up/Changing Hostname
- Editing the /etc/hosts file
- Search
- About This Site
- Latest Tutorials
3 ways to configure a network interface in Linux
Few things are more important to your machine than a good network connection. Here are three ways to configure the interfaces needed to make this happen.
Editor’s note: This article was written while James Brigman was a member of the Red Hat Accelerator program.
Great Linux resources
Almost any useful work that one would want to do with a Linux system requires a network interface. Want to browse the web, watch YouTube, stream video, audio or files? It’s all done over the network interface. RPM-based Linux distributions using Gnome have several fundamental ways to configure the network interface. I’m describing three ways in this article. All of the configuration methods require the entry of sets of numbers that allow the network interface to operate.
You will need three fundamental pieces of numerical information in order to minimally configure a network interface to work over IPv4 and more if you want to define things like IPv6, hostnames, or DNS servers. This article covers the bare minimum for IPv4. Those three fundamental numerical pieces are:
IP Address: The unique number defining the access point to your network interface. It has the form: xxx.xxx.xxx.xxx, where “xxx” are three, or fewer, numbers between 0 and 255. It’s possible for this number to be purely made up, but normally it takes a form that works with the other three numbers. If you are using a home router with DHCP, which is the typical default configuration, the router will “assign” the IP address to your network interface. You won’t have to enter the number at all.
Gateway: The unique number assigned to the network interface at the «other end of the wire» that your computer must communicate through. Again, it has the general xxx.xxx.xxx.xxx format and takes a form that also works with the other two numbers. If you are using a home router, your home router generates this number because it is the gateway through which you communicate with the wider world.
Netmask: The non-unique number that defines the network itself. This number can be automatically generated but is sometimes requested by the method you use to configure the interface. It, too, has the format xxx.xxx.xxx.xxx.
Note that I’m not going into the how of these numbers; I’m just telling you they are needed to configure the network interface. I’ll skip that so you can get on into the point of the article: Three ways to configure network interfaces. In each case, the numbers I use will be real numbers applicable to the system I used to write this article. I used CentOS 8 to generate the images, but everything you see here is the same in Fedora and Red Hat Enterprise Linux.
At installation time
The Anaconda installer prompts for network configuration and you can’t complete the installation without providing these numbers to the installer. Here’s the initial screen, using “Network & Host Name” in the rightmost column, third selection down:
How to Configure Network Settings in Ubuntu
When installing an Ubuntu server or desktop, it is important to know how to configure and view network settings. It’s also useful for troubleshooting problems with your Internet connection. Basic network configuration includes setting the IP address, the subnet mask for internal communication, and a gateway for connecting to external networks. In this article, I’ll give examples of the basic configuration you need to set up a network in Ubuntu, either from the command line or from the Ubuntu Network Manager GUI. The steps have been tested on Ubuntu 20.04 LTS up to Ubuntu 22.04 LTS, but they will also work on newer Ubuntu versions.
Basic network setup requires:
- Setting/Changing an IP address
- Setting up/Changing Hostname
- Editing a hosts file
Setting/Changing an IP address
There are several ways to set an IP address in Ubuntu. You can configure the network interface to use dynamic IP using a DHCP server, or you can manually set a static IP address.
Method #1: Network configuration on the command line
In Ubuntu, you can set your IP address through terminal commands.
First, type netstat -I to find the interface name. Then type the below command:
sudo ifconfig eth0 192.168.72.6 netmask 255.255.255.0
Then to add a default gateway, add the below command:
sudo route add default gw 192.168.72.1 eth0
Method #2: Network configuration using the GUI
You can set an IP address via the graphical user interface in Ubuntu. From the desktop, click on the start menu and search for Settings. From the Settings window, click on the Network tab. Then from the right pane, select the interface and click on the gear icon to open the settings for that interface.
From the IPv4 tab, you can select the Automatic (DHCP) radio button to allow the system to dynamically obtain the IP address.
If you want to set a static IP address, click on the Manual radio button. Enter the IP address, subnet mask, and a default gateway. Then click on Apply to save the current changes.
Method #3: Configure the network by editing /etc/interfaces file
Here is another method that you can use to configure the IP address. To set IP address dynamically, you have to edit /etc/network/interfaces. In /etc/network/interfaces, the basic configuration of interfaces is stored.
Edit the /etc/network/interfaces by entering the following command in the terminal.
sudo nano /etc/network/interfaces
Then add the following lines:
auto eth1 iface eth1 inet dhcp
Save the file and restart networking services using the below command.
sudo systemctl restart networking
To set a Static IP address, you have to edit /etc/network/interfaces
sudo nano /etc/network/interfaces
Add the below lines to /etc/network/interfaces.
auto eth1 iface eth1 inet static address 192.168.72.8 netmask 255.255.255.0 gateway 192.168.72.1 dns-nameservers 8.8.8.8 4.4.2.2
Save the file and restart networking services.
sudo systemctl restart networking
Setting up/Changing Hostname
The hostname of Ubuntu OS is configured in the file /etc/hostname.
To edit /etc/hostname, enter the below command:
This file contains only the hostname of the file, change the name, and then save it.
Editing the /etc/hosts file
Hosts file maps hostname to IP address locally. For instance, if you have a server in your local network, instead of remembering its IP, you can map its IP with a name in your /etc/hosts file. It will allow you to access that machine with a name instead of the IP.
To edit a hosts file, enter:
Add the server IP address and name in the hosts file in the following format.
Save the file and reboot the system to apply the changes.
That’s all you need to set up a network in Ubuntu. Those were the basic settings. There are many more options you can configure in your Ubuntu machine.
Search
About This Site
Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.