Home  >  Article  >  Computer Tutorials  >  Super detailed tutorial on setting static IP in Linux system!

Super detailed tutorial on setting static IP in Linux system!

WBOY
WBOYforward
2024-03-02 08:22:13876browse

Super detailed tutorial on setting static IP in Linux system!

Setting a static IP address in a Linux system is a key step to ensure a stable and reliable network connection. A detailed tutorial is provided below on how to set up a static IP address on 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

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

Step 2: Edit Network Configuration File

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

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

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

Step 3: Configure static IP

In the opened file, make the following settings:

  • Set 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 corresponding 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 DNS server:

    DNS1=8.8.8.8DNS2=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 and make 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 settings

Use the following command to verify that the static IP address is 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 the 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.

The above is the detailed content of Super detailed tutorial on setting static IP in Linux system!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete