How to Find and Change IP Address, Subnet Mask & Default Gateway of Linux Server

Sometimes we need to check the IP, Subnet mask and default gateway of our Linux machine and sometimes we need to change them as per our requirement. Here i will explain how to check and change these properties. If you want to change hostname of your Linux server, i would suggest to read attached article.

Check IP Address, Subnet Mask & Default Gateway

Launch PuTTY and connect to Linux server. Run ifconfig command.

#Check IP address and Gateway Mask
ifconfig

You will see output of this command like below screenshot.

check ip address of linux machine

Focus on the area which is highlighted in red colour. The IP address of this Linux server is 192.168.0.1 which is labeled as inet. You can see the subnet mask of this server which is showing 255.255.255.0 as netmask. We can also see the connection interface name of this machine that is ens33. The connection interface name will be used later in next section during changing IP addresses, subnet mask and gateway details.

Now we knew how to check the IP Address & Subnet Mask of your Linux computer. Now next step is to check the default gateway of this server. Run below command route -n to get the details of default gateway.

#Check Default Gateway
route -n

We can see the gateway IP is given in below screenshot for the same connection interface name ens33.

Check Gateway IP

Change IP Address, Subnet Mask & Default Gateway

We knew how to get the IP address, subnet mask and gateway details of Linux server. Now i will explain how to change these addresses if needed. We will use same command ifconfig to change the IP address and subnet mask. Before proceeding, make sure you have interface name and new IPs. You can get interface name from ipconfig command. The connection interface name of my machine is ens33 as shown in above screenshots. Run below command to change these two values.

#Replace ens33 to your connection interface name. You can get it from ifconfig command.
sudo ifconfig ens33 192.168.209.10 netmask 255.255.255.0

change IP
We can see command executed successfully. You can validate the new IP address by running ifconfig command again. I have not changed netmask and kept same. If you want to change it please pass your netmask address.

check ip post change

Now we can see we have changed the IP address and netmask address for this Linux server. Next we can check the gateway address to validate what will be the impact on gateway post changing the IP address and netmask address. Run route -n again to get the details.

route -n

We can see gateway address is not set yet and the one showing on first section is not showing now. So let’s change the gateway address for this server. Run below command to change the gateway address.

#change the name of gateway address. Change the connection interface name from ens33 to your name.
sudo route add default gw 192.168.209.250 ens33


Once command will be executed successfully, you can validate this change by running route -n command again.

validate the change post changing gateway IP Address
We can see the new gateway address in above screen. These are the commands that can be used to check and change the IP address, netmask address and gateway address.

Related Articles

Please comment us if you have any question. Also i hope you like this article. Please follow us on our facebook page and on Twitter handle to get latest updates.

Manvendra Deo Singh
Follow me:

You may also like...

3 Responses

  1. Asif says:

    Great post. Extremely useful and I even referred some of my readers to this blog for better understanding of how to change router IP in Linux. However, those who have Windows can learn more about their default gateway address in my latest post at router-reset (https://www.router-reset.com/how-find-your-default-gateway-address/)

  2. khush says:

    sir i have facing network is unreachable after changing deafult gateway

  1. September 15, 2020

    … [Trackback]

    […] Read More: techyaz.com/rhel/check-change-ip-address-subnet-mask-default-gateway-linux-server/ […]

Leave a Reply

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