Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure static Network connection in Linux system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to configure a static network connection in the Linux system. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

Step 1: check the network connection

The ping command is a well-known program that can quickly check network connectivity. Enter the following on the command line:

Ping-c3 opensource.com

The-c3 option indicates that you only ping three times.

If you connect to the Internet, you will receive a similar packet response.

Step 2: check the connection information

You can check the network information with the ip add command.

Run this command to display device information, IP address, and so on. You will need this kind of information (such as device information and IP address) to set up a static connection later, so keep it in mind.

Step 3: check the network information

The network information can be found in the / etc/sysconfig/network-scripts directory by entering the following command:

Ls / etc/sysconfig/network-scripts

For example, this screenshot shows ifcfg-enp0s3 and ifcfg-lo, but these depend on the Linux you are running and how the device is set up.

Step 4: show available connections

You can use the nmcli tool to display the available connections to the current network. Enter the following command:

Nmcli con show

This screenshot shows two devices active: enp0s8 and enp0s3, which are called Wired Connection 1 and 2. But this may be different from your display, depending on how the Linux environment is set up.

Step 5: check that the network connection is open

You can use the above ping command to check whether you can receive packets, but now we need to use the systemctl command to call network to monitor, update the network status, and troubleshoot. The command is:

Systemctl status network

If there is no problem with the network support program, you will see that the status is active when you run this command.

Step 6: add a static network connection

Now you are ready to add a static network connection. Using the device name obtained from ip add in step 2, enter the following command to add a new connection:

Nmcli con add con-name "SomeName" ifname YOUR_DEVICE autoconnect yes type YOUR_CONNECTION_TYPE

Modify the SomeName,YOUR_DEVICE and YOUR_CONNECTION_TYPE in the command according to your actual configuration.

Step 7: verify that the connection has been added to the network script path

You can use the nmcli tool to modify new connection information. Through the following command:

Nmcli con mod

This command actually modifies the network configuration script in the / etc/sysconfig/network-scripts directory, which is another way to modify the connection information.

View the / etc/sysconfig/network-scripts path again by entering the following command:

Ls / etc/sysconfig/network-scripts

You can see that the connection ifcfg-MyFavoriteCafe has been added.

Step 8: make sure you can see the connection

Check to see if the MyFavoriteCafe is a visible available connection. Use the following command to start the connection. Please note that SOME_CONNECTION_NAME should be your real connection name (in this case, MyFavoriteCafe)

Nmcli con up SOME_CONNECTION NAME

You can also turn it off with the following command:

Nmcli con down SOME_CONNECTION NAME

When you add a new connection, set autoconnect to true so that if the network service is restarted, it will be enabled automatically.

So far so good. The connection is displayed when you run the following command:

Step 9: change the connection to static

Open the file / etc/sysconfig/network-scripts/ifcfg-SOME_CONNECTION_NAME (in this case, MyFavoriteCafe) with a text editor such as Vim, Emacs, or Nano.

To make the connection static, you need to modify one parameter and add three more:

Change BOOTPROTO to static.

Add IPADDR. That is, the static IP address you want to set, which can be seen through the ip add command.

Add NETMASK. This is the subnet mask and can be found through the ip add command.

Add GATEWAY. This is the IP address of the default gateway and can be found through ip add.

You may also need to add DNS,PREFIX or other information, depending on how your network and computer are set up.

When you are done, save the file. Restart the network with the following command:

Systemctl restart network

Check status:

Systemctl status network

Step 10: confirm that the new connection is active

This has to be done! Make sure your new connection is working properly. Run the nmcli con show command again to enable the new connection.

You can also use a ping URL to verify that the connection is working.

Finally, you can check the device information with the following command:

Nmcli dev show DEVICE_NAME

Where DEVICE_NAME should be the real name of your network device.

After reading the above, do you have any further understanding of how to configure a static network connection in a Linux system? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report