How to change the IP address and gateway in Ubuntu?

To change the IP address and gateway on an Ubuntu system, you can follow these steps:

  1. You can open a terminal window by using the shortcut Ctrl + Alt + T.
  2. Enter the following command to view the current network configuration information:
ip addr

Or alternatively

ifconfig
  1. Locate the network interface you wish to modify, usually it’s either eth0 or ens33, and then use the following command to change the IP address and gateway:
sudo ifconfig <interface_name> <new_ip_address> netmask <netmask> up

For example:

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
  1. Then use the following command to add the gateway:
sudo route add default gw <gateway_ip>

“For example:”

sudo route add default gw 192.168.1.1
  1. The configuration file for DNS resolution, located in the /etc directory.
nameserver 8.8.8.8
nameserver 8.8.4.4
  1. Restart the network service to apply the configuration.
sudo systemctl restart networking

You have successfully modified the IP address and gateway of the Ubuntu system. Please make sure the new network configuration information is correct to avoid any network connection issues.

Leave a Reply 0

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