How to configure static IP addresses on Linux
When you need a Linux system with a static IP address instead of a dynamically set address by DHCP, all you need to do is make some configuration changes and reboot the system. Follow these steps to make the conversion.
IP addresses on Linux systems are usually automatically assigned by the server Dynamic Host Configuration Protocol (DHCP). They are called "dynamic addresses" and can be changed whenever the system is restarted. However, when a system acts as a server or is managed remotely, it is more convenient to have a static address. Static IP addresses provide a consistent and consistent connection for users and applications.
Fortunately, the steps needed to change the Linux system IP address from dynamic to static are quite easy. However, the process will vary slightly depending on the distribution you are using. Today's article will look at how to manage this task on both Red Hat systems (RHEL) and Ubuntu.
There is no simple command to determine if the IP address on a Linux system is assigned by DHCP or a static address. If the IP address on the Linux system changes when the system restarts, this is obviously a dynamic address. But even dynamic addresses may not change. The best way is to look at the configuration file.
RHEL 8
To configure a static IP address on a Red Hat system, start by listing the connection of Network Manager. The nmcli command shown below will list the network connections and devices on the system. Note that the device name and connection name are not the same.
$ nmcli dev status DEVICE TYPE STATE CONNECTION wlo1 wifi connected Comtrend7FB9 virbr0 bridge connected virbr0 enp3s0 ethernet unavailable -- lo loopback unmanaged -- virbr0-nic tun unmanaged --
To change the network interface from dynamic to static, you need to edit the file in the / etc / sysconfig / network-scripts directory, representing the common interface. In this example, the file is called ifcfg-Comtrend7BF9 ( ifcfg- followed by the name of the connection). The "BOOTPROTO = dhcp" boot protocol line needs to be changed to "BOOTPROTO = static" . In addition, the IP address used must be added to the file. The end result will look like this:
HWADDR=7C:67:2A:CF:EF:9F ESSID=Comtrend7FB9 MODE=Managed KEY_MGMT=WPA-PSK SECURITYMODE=open MAC_ADDRESS_RANDOMIZATION=default TYPE=Wireless IPADDR=192.168.0.22 PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=Comtrend7FB9 UUID=2f5a6217-37c7-449f-bfaa-1d3fa5283482 ONBOOT=yes
Run systemctl restart NetworkManager for changes to take effect.
Ubuntu 18.10
The nmcli command (network manager command line interface) can be used to list network interfaces on the Ubuntu system. In the output below, we see both the loopback interface and the public network listed. Devices on the system may have a different name, reflecting the location of the hardware.
Ubuntu> nmcli d DEVICE TYPE STATE CONNECTION enp0s25 ethernet unmanaged -- lo loopback unmanaged --
To check the network interface configuration settings on the Ubuntu system, you will use the following command:
Ubuntu> cat /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto enp0s25 iface enp0s25 inet dhcp
As you can see from the last line in this output, the eth0 interface is currently assigned by DHCP. To change the settings successfully, you will change "dhcp" to "static" and add some other lines. For example, in the file like the image below, 'dhcp' has been changed to 'static' and specifies the IP address you want to use with other settings:
# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto enp0s25 iface enp0s25 inet static address 192.168.0.11 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255
Restart the network or system service for the changes to take effect.
Changing network settings should only be done when they do not affect existing connections and you can back up changes if needed. Make a copy of any configuration file before you change it. Then give the file a recognizable name.
Hope you are succesful.
You should read it
- How to assign static IP addresses in Windows 7, 8, 10, XP or Vista
- Here's how to check if your IP address is static or dynamic
- How to Configure a Static Internet Protocol (IP) Address on a Computer
- Static IP address or dynamic IP more secure?
- Set up the Linksys router with a static IP address
- Instructions for setting static IP addresses, changing DNS
- How to assign a static IP address in Windows 11, 10, 8, 7, XP or Vista
- Set static IP settings for Windows XP, 7, 8, and 8.1 computers
May be interested
- 7 best antivirus programs for Ubuntuviruses can still be spread, especially if you have a samba server (to share windows files on linux) or external devices often interact with both linux and windows.
- How to check for simple Linux server performancethere are many options for virtual private servers or professional servers in the market, so how do i know which server is the best and suitable for me?
- Check the current user on Linuxin linux, you can perform simple tasks such as checking the current user in many ways. this tutorial will show you how to use some of the quickest and easiest ways to check users on linux.
- How to display the date and time in Linux Terminallet's take a look at the advanced uses of the date command in the command line and how to use it in the shell script to perform more functions than simply displaying the time.
- How to check the time of shutdown and reboot in Linuxthere are many reasons why you might want to find out when your linux computer is off, reboot or how long it will run. in most cases, this information is invaluable in debugging a problem.
- How to run Linux desktop using Windows Subsystem for Linuxone solution to this problem is to use windows subsystem for linux, but this tool does not have a desktop environment.