Setting IP Address in Linux With Command Line

How to Set IP Address on Linux Using Command Line

In order to be able to connect with other devices on the network, a computer must have IP Address. IP Address is a series of numbers binary which is used as the identification address for each computer or host in the network.

On Debian Linux and derivatives such as Ubuntu and Kali Linux, configure IP Address located in file interfaces. To edit the file and set the IP Address, you need text editor to open it. You can use text editor anywhere like nano, pico, vim and so on. In this tutorial I use text editor nano, because it is easier to use.

Type the following command to open the file interfaces, use command sudo if you don’t use user root:

nano /etc/network/interfaces

Then the interfaces file will open, if the IP Address is not set during the installation process and is still using the settings dynamic or DHCP, there will be a configuration line like the following.

auto eth0
iface eth0 inet dhcp 

To change it to static, change the text “dhcp” Becomes “static”and add the IP Address configuration line below it, as follows. Customize IP Address, nestmask, gateway and others with the network you are implementing or want to create.

auto eth0
iface eth0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.254
        dns-namerservers 192.168.1.1

If you want to use two network cards (Network Interface Card) or more, just add the IP Address configuration line again under the existing configuration with the name interfaces eth1, eth2 and so on, as follows.

auto eth0
iface eth0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.254
        dns-namerservers 192.168.1.1
auto eth1
iface eth1 inet static
        address 192.168.100.1
        netmask 255.255.255.0
        network 192.168.100.0
        broadcast 192.168.1.255

Save the configuration by pressing the combination CTRL + O on the keyboard, and press enter. Then exit text editor it by pressing CTRL+X.

Next is to add DNS to the file resolv.conf. In order to be able to connect to the internet we must add DNS from the ISP that we use, or may also use Google DNS. But if only for local network or LAN, just add it with computer or computer DNS server itself.

Type the following command to open the file resolv.conf:

# nano /etc/resolv.conf

Then the file will open resolv.confjust delete the contents of the file and enter the DNS IP that will be used, as follows.

nameserver 192.168.1.1

If so, save the file by pressing the combination CTRL + O on the keyboard and then enter, then exit by pressing CTRL+X.

So that the configuration can be applied immediately, restart network services with the following command:

# /etc/init.d/networking restart

Make sure it’s not there error emerging.

Then check the configuration IP Address it by typing the command ifconfig.

ifconfig

Then it will appear IP Address and others as previously configured, as shown below.

Setting IP Address With Command Line on Linux
Display the configured IP Address

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *