How To Configure Static IP Address On Ubuntu and CentOS 8

We can assign and configure static IP Addresses in Linux as well as ubuntu using the command line. Let’s see, how to change the IP Address in CentOS 8.

How To Configure Static IP Address On Ubuntu and CentOS 8

Why you need a static IP Address? Suppose, whenever you take a reboot of your machine. The new IP address will be assigned from the DHCP pool and you don’t want the new IP address. The solution is to set the static IP to the machine. 

Check Out: How To Install MySQL 8 Server On Ubuntu 20.04 /18.04

Assign Static IP On CentOS 8:

We need to configure the IP address on the CentOS 8 /7. you can do that in different ways. I will show you all the ways of doing this. 

1. Using the NMTUI Command:

You just need to type the nmtui command on the Linux machine. this will open the network interface where you can assign the static IP address. Run the below command from the terminal. 

sudo nmtui

static ip address

We need to “Edit a connection” and hit “Enter”.

 static ip ubuntu

Use tab to reach the “Edit” then Enter. you will have to use the “Tab” than IPv4 configuration, you will see the “Show“. you have to select that and choose “Manual“.

Check Out: How To Send Tomcat Logs To S3 Bucket From EC2 Instance

Now you can assign the IP Address with Gateway and DNS settings. Once it’s done. Click on “OK”.

static ip in linux

Click on “Back” and you will see an “Activate connection“. Select it and click on “Activate“. 

configure static ip address

Select “Back” then “quit“. 

Check the IP Address using ip a or ifconfig command. 

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:83:20:f0 brd ff:ff:ff:ff:ff:ff
inet 192.168.185.147/24 brd 192.168.185.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::1d27:7cb8:18d0:49c7/64 scope link noprefixroute 
valid_lft forever preferred_lft forever

You can reboot the machine and you will get the same IP when you logged into the machine. 

Static IP On Ubuntu 20.04:

We will change the IP Address in the Ubuntu machine using the below commands. First of all, you will need to check the ethernet interface name using ifconfig command. 

ubuntu@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.185.146 netmask 255.255.255.0 broadcast 192.168.185.255
inet6 fe80::98e3:12a6:1afb:b439 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:b3:7d:2f txqueuelen 1000 (Ethernet)
RX packets 2398 bytes 2931505 (2.9 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1813 bytes 146200 (146.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 369 bytes 37056 (37.0 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 369 bytes 37056 (37.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Check Out: How To Configure Free SSL Certificate Using Certbot On Ubuntu

Our Ethernet interface name is ens33 and we will use the below command to assign the manual IP address. 

sudo ifconfig ens33 192.168.185.147 netmask 255.255.255.0

You can see our IP Address has changed. 

ubuntu@ubuntu:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host 
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:b3:7d:2f brd ff:ff:ff:ff:ff:ff
inet 192.168.185.147/24 brd 192.168.185.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::98e3:12a6:1afb:b439/64 scope link noprefixroute 
valid_lft forever preferred_lft forever

If you require to change the default gateway, use the below command. 

sudo route add default gw 192.168.185.1 ens33

So, we will see the new settings, we need to check the routing tables using route -n command.

We’ve successfully assigned the static IP address on both Linux as well as ubuntu. 

That’s it.

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment