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 use the nmcli command to configure the network in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to use the nmcli command to configure the network in Linux. It is very detailed and has a certain reference value. Friends who are interested must read it!

The nmcli command is the command after redhat7 or centos7, which can complete all the configuration work on the network card, and can be written to the configuration file and take effect permanently.

1. Network interface name

In centos7 or Red Hat 7, Ethernet is identified with the beginning of en, and the previous version begins with eth. At the same time, wl identifies the waln interface and ww identifies the wwan interface.

Next is the network card type, p for pci physical location, o for onboard, s for hot plug. The last number represents the index, id, or port. For example, the author's virtual machine on the enp0s3,pci network card slot3.

If you can't determine a fixed name, use the traditional ethn method.

2. View network configuration

Use ip addr to display the ip address, ip addr show eth0 to display the network card eth0, ip-s link show eth0 to show the connection status, and you can see the packet. Netstat-I can also list network cards and view data traffic.

3. View routing and troubleshooting

Ip route checks the routing table of the system

Ping gateway address. Ping-c4 is ping 4, and timeout 4 is a timeout of 4 seconds.

The tracepath or traceroute command tracks the network status of the target host

4. Ports and services

The TCP service uses the socket .socket as the endpoint for communication, which consists of IP addresses, protocols, and ports. The server usually listens on the standard port and the client uses the randomly available port. Standard ports are listed in / etc/services.

View the listening port: ss and netstat commands.

5. Use nmcli to view the network

Networkmanager is a daemon for monitoring and managing the network. You can communicate with networkmanager through the command line and graphical interface, and save the configuration file in the / etc/sysconfig/network-scripts directory.

Use nmcli to view network information:

Nmcli con show View Network Interfaces

Nmcli con show-active View active Network Interfac

Nmcli con show "enp0s3" to view details of the enp0s3 network

Nmcli device status views the information of the device

Nmcli device show enp0s3 views information about enp0s3 devices

6. Use nmcli to configure the network

Multiple network connections (profiles) can be configured for network devices, but only one can remain active at a time.

Create a new "default" connection and use dhcp to get the network.

Nmcli con add con-name "default" type ethernet ifname eth0

Create a static connection, configure static IP, and set not to connect automatically.

Nmcli con add con-name "static" type ethernet ifname eth0 autoconnect no ip4 172.25.0.12 take 24 gw4 172.25.0.254

Change to static link.

Nmcli con up "static"

Change to dhcp link.

Nmcli con up "default"

View usage information.

Nmcli con add help

If you modify the configuration, you will not elaborate on it too much.

Nmcli con mod

Summary of nmcli commands:

7. Edit the network configuration file

An interface profile controls the software interface of a single network device. A network device can have multiple profiles, but only one is active.

Img

Ifcfg profile options (secondary IP address adds options in the configuration file to 1)

Configuration process:

A. Modify the ifcfg configuration file

B. Use the nmcli command to make the configuration effective or restart the process

Nmcli con reload

Nmcli con down "ID", nmcli con up "ID"

C. Verify the network configuration through ping

8. Hostname and name resolution

Hostname View Hostname

Hostnamectl status to view host information

Hostnamectl set-hostname set hostname

The static hostname is stored in the / etc/hostname file. Name resolution is used to convert hostnames to IP addresses and vice versa, as defined in / etc/hosts.

You can use getent hosts your_hostname and / etc/hosts to test hostname resolution.

If not in / etc/hosts, the / etc/ resolv.conf file is looked for.

The above is all the contents of the article "how to configure a network with nmcli commands in Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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

Development

Wechat

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

12
Report