How to configure Kali Linux to use a static IP address
What are advantages of a static IP address usage?
On a local network, a static IP address allows you to use the Web server, SSH, FTP and other network services without having to get to know IP of a system on which these services are running each time. If you do not use these services, then there is no need to configure a static IP.
A static address for a particular computer or other device can be set in several ways:
- in the settings of your router, bind the MAC address to the IP address: in different routers the configuration process may be slightly different, but usually these functions are located in the Local network (LAN settings) -> DHCP server -> The list of manually assigned IP addresses bypassing DHCP.
- setting up a static IP address in Network Manager
- setting up a static IP address in the command line
Manually assigning IP addresses bypassing DHCP in the router
The specific steps for binding the MAC address to the IP address in the router depend on the device model. Therefore, if you have any questions or you can not find the desired setting in your router, then refer to its manuals. In this case, the actions do not depend on the device to which you want to assign a permanent IP address, since all the configuration is performed in the router. Also, after resetting the settings on the device to which the permanent IP address was assigned (for example, when reinstalling the OS on the computer or Factory Reset of the phone), then the binding of the IP address to the device is preserved, since the MAC address is always unchanged.
This method is not suitable for virtual machines, even if a network connection of the Bridge type is used.
Configuring a Static IP Address in Network Manager in Kali Linux
In Linux, a static address in a graphical environment can be set in the Network Manager settings. To do this, click on the arrow in the upper right corner of the screen, in the menu that appears, click on ‘Wired Connected’, and then on ‘Wired Settings’:
A new window will open, in it click on the gear icon:
Another window will open, in which go to the IPv4 tab:
then enter the desired static IP in the ‘Addresses’ field, it should match your network, for example, if the router (default gateway) has the address 192.168.0.1, then the selected address should be 192.168.0.*, if the router has the address 192.168.1.1, then the selected IP should be of the form 192.168.1.* etc. Next, write down the ‘Netmask’, for most tasks 255.255.255.0 is suitable, also write the ‘Gateway’, which is the IP router, an example:
If you wish, you can also set the DNS server settings, but this is not mandatory.
When done, click the Apply button.
By the way, to get to know the gateway (the IP address of the router) run the command:
The following will be displayed:
default via 192.168.0.1 dev eth0 proto dhcp metric 100 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.194 metric 100
After the ‘default via’ line, the IP router will follow, in my case it is 192.168.0.1.
To apply made changes enter:
sudo systemctl restart NetworkManager
Check your current local IP with the command:
Configuring a Static IP Address in the Kali Linux Command Line
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:
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
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:
Finally, now you can check:
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
Last Updated on
- How to update Kali Linux (66.9%)
- How to replace Default Desktop Environment with Cinnamon in Kali Linux (66.9%)
- How to install Guake in Kali Linux (66.9%)
- How to Install Total Commander Counterpart in Kali Linux (66.9%)
- How to install Router Scan (66.9%)
- How to switch between Internet connections in Windows (RANDOM - 14.1%)