If for some reason you do not use Network Manager (for example, if you use Linux without a desktop graphical environment), you can configure a static IP address on the command line.
To do this, open the /etc/network/interfaces file with any text editor:
sudo vim /etc/network/interfaces |
Only four lines should be added to this file. Example strings:
auto eth0 iface eth0 inet static address 192.168.0.100/24 gateway 192.168.0.1 |
Let us examine them in more detail. eth0 is the name of the network interface. If there is only one network card, then in Debian (i.e., in Kali Linux too), this interface is called eth0. The second network interface is named eth1, etc.
If you are not sure, you can find the name of the wired network interface with the command:
ip a |
In the second line, you need to use the same interface name (eth0).
Further in the third line, 192.168.0.100 is the IP that we want our system to always have. And /24 is an alternative way to set netmask. These characters correspond to 255.255.255.0.
As you might guess, in the last, fourth line, 192.168.0.1 means a gateway.
All these data need to be changed to fit your needs.
For the changes to take effect, issue the command:
sudo systemctl restart networking.service |
Let’s check:
ip a |
As you can see, the interface is really assigned the required IP and now it will be saved after each reboot.
However, there is currently no Internet connection, because we have not configured DNS. These settings are made in the /etc/resolv.conf file. If you already have Network Manager installed, then instead of /etc/resolv.conf there is a link to /run/NetworkManager/resolv.conf
sudo rm /etc/resolv .conf |
Open /etc/resolv.conf with any text editor:
sudo vim /etc/resolv .conf |
and add the line:
nameserver 8.8.8.8 |
Finally, now you can check:
ping google.com |
On Kali Linux, the made changes do not disappear after the download. If they disappear, the file /etc/resolv.conf can be protected from writing:
sudo chattr +i /etc/resolv .conf |