Super detailed tutorial on setting static IP in Linux system!

Setting up a static IP address in a Linux system is an important step in configuring network connections. Here is a super detailed tutorial on how to set up a static IP address for your Linux system:

Step 1: Determine the network interface
First, determine the name of the network interface for which you want to set a static IP address. You can view the network interfaces available on your system using the following command:

ifconfig -a

or

ip addr show

Note the name of the network interface you want to set up, such as "eth0" or "ens33".

Step 2: Edit the network configuration file
Open the network configuration file to edit network settings. In most Linux distributions, network configuration files are located in the "/etc/sysconfig/network-scripts/" directory and are prefixed with "ifcfg-" followed by the network interface name.

Open the appropriate file using your favorite text editor, for example:

sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

Step 3: Configure Static IP
In the file that opens, make the following settings:

  • Set a static IP address:

    IPADDR=192.168.1.100

    Replace "192.168.1.100" with the static IP address you want to set.

  • Set subnet mask:

    NETMASK=255.255.255.0

    Replace "255.255.255.0" with the appropriate subnet mask based on your network configuration.

  • Set default gateway:

    GATEWAY=192.168.1.1

    Replace "192.168.1.1" with your default gateway address.

  • Set up DNS server:

    DNS1=8.8.8.8
    DNS2=8.8.4.4

    Set one or more DNS server addresses according to your needs.

Save and close the file.

Step 4: Restart the network service.
Execute the following command to restart the network service so that the configuration changes take effect:

sudo systemctl restart network

Alternatively, depending on your Linux distribution, you can use the following command:

sudo systemctl restart networking

Step 5: Verify Setup
Use the following command to verify that the static IP address was set up successfully:

ifconfig eth0

Replace "eth0" with your network interface name.

You will see the network interface information displayed, including the static IP address set and other configurations.

Through the above steps, you can set a static IP address in your Linux system. Please make sure to configure it accordingly based on your network environment and needs. This will ensure that the system uses the specified static IP address for network connections.

Guess you like

Origin blog.csdn.net/tiansyun/article/details/131447275