Set IP Address in Ubuntu: Command Line Guide

In Ubuntu system, you can set the IP address using the command line with either ifconfig or ip command. Here are the steps to set the IP address using these two commands:

Set the IP address using the ifconfig command.

  1. Open the terminal and enter the following command to view information about the current network interface:
ifconfig
  1. Option: Interface eth0
  2. Ethernet port 0, slot 3
  3. the first network interface, or primary network interface
  4. one hundred and ninety-two dot one sixty-eight dot one dot one hundred
sudo ifconfig eth0 192.168.1.100
  1. eth0 refers to the first Ethernet network interface available on a device.
  2. The subnet mask is 255.255.255.0.
sudo ifconfig eth0 netmask 255.255.255.0
  1. The IP address 192.168.1.1
sudo route add default gw 192.168.1.1
  1. The configuration file for resolving domain names on a Unix-like operating system is /etc/resolv.conf.
sudo nano /etc/resolv.conf

Add the following content to the file (replace it with your DNS server address):

nameserver 8.8.8.8
nameserver 8.8.4.4
  1. Restart the network service to make the settings take effect:
sudo service networking restart

Set the IP address using the “ip” command.

  1. Open the terminal and enter the following command to view information about the current network interface:
ip addr show
  1. The first Ethernet interface
  2. Ethernet port 0, slot 3
  3. Ethernet Interface 0
  4. One hundred and ninety-two dot one hundred and sixty-eight dot one dot one hundred
sudo ip addr add 192.168.1.100/24 dev eth0
  1. The IP address 192.168.1.1
sudo ip route add default via 192.168.1.1
  1. configuration file for resolver settings
  2. Restart the network service to apply the settings (same as the steps to set ifconfig).

After completing the above steps, you have successfully set the IP address for the Ubuntu system.

bannerAds