- Home
- Linux
- Networking
- How to manage networking confi ...
Network configuration in Linux has always seemed daunting, but it’s not the case honestly. In this article, we will see how easy it is to perform networking configuration in Linux ubuntu server.
We will be performing all the networking config on Ubuntu Linux. But it’s relatively applicable to other Linux distribution as well. We will look at the setup of the static IP address, network interface, ethernet interface, and more. Let’s learn Ubuntu networking!
Note: The examples below are not done on Cloud Server, but rather locally on a VM Simulator i.e. VMware.
Prerequisite
- Must have Linux OS or its Virtual Machine (YouTube Tutorial)
- Basic Linux commands hands-on. (Check here)
Table of Content
Table of Contents
Networking Configuration in Linux Ubuntu
Identify Ethernet Interface
First, we need to create a shell script file. Execute the following command to create and open a shell script with ‘nano’ text editor.
ip addr
Another way to show available network interfaces is through the following IP command:
sudo lshw -class network
The network interface that we are concerned with will be against the ‘logical name’. In the image shown, it is ens33
Network Config in Linux: Assigning IP Address
Temporary IP Address Assignment
We can temporarily assign an IP address to our server. This assignment is not permanent and will be reset once the server is rebooted. For temporary IP configuration, execute the following command:
sudo ip addr add 10.114.36.120/24 dev ens33
Once the temporary IP is assigned, it will override the default one. To start and stop the network connection link, execute the following commands:
ip link set dev ens33 up
ip link set dev ens33 down
To ensure the new network configuration has taken effect, you can check the network interface with the following command:
ip addr
Furthermore, if you are on Runlevel 5, then you can even check through the browser. If the IP link is down, the browser won’t load any pages.
Configure Default Gateway IP Address
IP configuration for the default gateway executes the IP command shown below. Note that the default gateway IP address should be according to the network IP assigned previously.
sudo ip route add default via 10.102.66.1
The below IP command is to confirm the change in network IP for the default gateway.
ip route show
Change DNS Nameserver in Ubuntu Server
If you want to change your DNS server IP for the temporary IP assigned, then open /etc/resolv.conf file with the following command:
sudo nano /etc/resolv.conf
Then at the bottom change the nameserver IP to an appropriate one, such as:
nameserver 8.8.8.8
nameserver 8.8.4.4
Afterward, you can run the ping command to see if the connection is maintained. However, the nameserver shown above is just to demonstrate how the DNS nameserver is changed. You should change it to a server-appropriate server address.
Reset all Network Settings in Ubuntu Linux
In order to reset all network settings in the Ubuntu Linux server to the default one, execute the following command:
ip addr flush ens33
Although, the above command would not reset the DNS nameserver IP in /etc/resolv.conf file. For that simply reboot your server or reset it manually.
Network Configuration Using the GUI
Previously we configured network settings for the Ubuntu Linux server through the command line. Now we will be configuring network interface using GUI.
How to give a Static IP Address
Let’s see how to configure static IP address. First, open up the Settings >> Network >> Wired setting icon. Refer to the image shown below. Go to the IPv4 tab and then select the ‘Manual’ option to assign a static IP address.
Here you should give the appropriate static IP, netmask, and default gateway address. Take reference from the image below:
After you are done, check the IP address from the ip addr command.
How to give a Dynamic IP Address through DHCP Server
Assigning dynamic IP address in Ubuntu Server through GUI works the same way as assigning static IP.
Open the Settings >> Network >> Wired setting icon. Then go to the IPv4 tab and select Automatic (DHCP). That’s it!
As the name suggests, the DHCP server will automatically assign all the relevant IP addresses wherever needed. Take reference from the image below.
Changing Hostname in Ubuntu Linux
It’s very easy to change a hostname in Linux. Using a text editor like Vim or nano, open hostname file with the below command:
sudo nano /etc/hostname
In this file, you will see your current hostname. Simply change it and save it. You may want to reboot your Linux Server before you can see the change.
Firewall Setup in Linux
A firewall is known for filtering good from bad incoming and outgoing traffic requests. It’s an essential step in fortifying your server’s security and a must to implement.
Allowing Various Protocols Traffic from the Firewall
The first thing we need to ensure is that ufw is installed on our Ubuntu server.
To verify ufw is running on your server, execute the following command:
sudo ufw status
If the above command returns statement as follow:
ufw: command not found
Then the firewall is not set up or enabled on your server. First, you need to install ufw and then enable it to start the firewall. For that, execute the following command:
sudo apt-get install ufw
sudo ufw enable
But if the ufw is already installed and enabled, then you still need to make sure that incoming traffic is allowed through various protocols.
For that, execute the following commands.
sudo ufw allow OpenSSH
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 990/tcp
sudo ufw allow 40000:50000/tcp
The above commands will open up some ports and start running services to receive traffic.
- OpenSSH will be enabled if you want to connect to your server using SSH protocol.
- On ports 20 and 21, your FTP protocol would be running.
- Port 990 would be used for TLS (Transport Layer Security).
- Lastly, ports ranging from 40000 to 50000 are enabled for later services to be assigned to them.
After setting all the traffic rules, let’s check the status of our Firewall.
sudo ufw status
Something like the one below should show up. Meaning that we have successfully enabled and configured our server’s Firewall.
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
990/tcp ALLOW Anywhere
20/tcp ALLOW Anywhere
21/tcp ALLOW Anywhere
40000:50000/tcp ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
20/tcp (v6) ALLOW Anywhere (v6)
21/tcp (v6) ALLOW Anywhere (v6)
990/tcp (v6) ALLOW Anywhere (v6)
40000:50000/tcp (v6) ALLOW Anywhere (v6)
And that’s a wrap!
Again, these commands will only work on a LINUX terminal on Ubuntu server. And a common way to run Linux with Windows is to start a Virtual Machine using VMware.
I hope this article helped you How to manage networking configuration in Linux Ubuntu. You may also want to read about How to add Users, Group, and Linux Processes & Scheduling Algorithm. Please like this article and leave your reviews in the comment section below.
Have a great one!
Recent Comments
Categories
- Angular
- AWS
- Backend Development
- Big Data
- Cloud
- Database
- Deployment
- DevOps
- Docker
- Frontend Development
- GitHub
- Google Cloud Platform
- Installations
- Java
- JavaScript
- Linux
- MySQL
- Networking
- NodeJS
- Python
- Python Flask
- Report
- Security
- Server
- SpringBoot
- Subdomain
- TypeScript
- Uncategorized
- VSCode
- Webhosting
- WordPress
Search
Recent Post
Understanding Linux Scheduling Algorithm: A Comprehensive Guide
- 13 June, 2023
- 3 min read
How to add routing in Angular
- 9 May, 2023
- 4 min read
What is Data at Rest in Cloud
- 13 March, 2023
- 2 min read
Featured Videos
All Tags
Amazon Web Services
Angular
API
AWS
Bash
Bash Scripting
Big Data
Cloud Server
Cluster
Command Line
CRUD
Database
Deployment
DevOps
Docker
Elementor
GitHub
Google Cloud
Google Cloud Platform
HBase Database
Header
installation
JasperReport
Java
JavaScript
Linux
Local Server
MySQL
NodeJS
npm
Programming
Publish
Puppeteer
Python
S3 Bucket
Security
SpringBoot
SSH
Terminal
ternary operators
TypeScript
Virtual Machines
Webhosting
Windows
WordPress