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

Linux Network Management-- basic commands of Network Management

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Three kinds of network management commands are mainly used in Linux: 1.ifconfig, route and netstat belong to traditional network commands with single function, 2.ip and ss belong to comprehensive network commands, 3.nmcli is suitable for integrated network commands in RHEL7, and network management can be realized through configuration files.

This paper mainly explains these three types of network management commands and related configuration files.

Note: the network parameters modified by the command will be lost after the network service is restarted, and only the network parameters modified by the configuration file can be permanently valid.

1-1. Ifconfig command

Purpose: view or configure network interface parameters

Format:

Ifconfig [interface] [up | down] View the specified network interface parameters and set the network interface status

Common options:

-a: displays all network interface information

-s: displays network interface statistics

The default ifconfig only shows the active network interface, and does not disappear to turn off the network interface parameters.

Ifconfig INT address configuration specifies the IP address of the network interface

Ifconfig INT IP/MASK or ifconfig INT IP netmask MASK modifies the IP address of the specified device

# when configuring an IP address, the keyword network must be used if the mask is represented in dotted decimal

One-two. Route command

Purpose: view or configure routing entries on this machine

Format:

Route View Route entry

Options:

-n: the domain name is not resolved and is displayed as an IP address

Route add-net |-host | default TARGET [netmask MASK] [gw GW] [mertic N] [dev INT]

Route del-net |-host | default TARGET [netmask MASK] [gw GW] [dev INT]

Add or remove route entries

Host routing entries use the keyword-host, network routing entries use the keyword-network, and default routing entries use the keyword default

Mertic N: used to specify route entry metric

Dev INT: specify the battle interface

Add host routing entry route add-host 1.1.1.1 gw 10.10.10.1 metric 15 dev eth2

The next hop address is 10.10.10.1, the routing entry metric is 15, and the outbound interface is eth2

Network routing entry route add-net 3.3.3.0 lap 24 metric 7 dev eth0

The metric is 7 and the outbound interface is eth0

Delete a network route entry

1-3. Netstat command

Function: view the network properties of this machine by specifying options

Format: netstat [options]

Common options:

-n: display IP and port in numbers

-t: show tcp connection

-u: show udp connection

-l: Port in listening state

-a: all statu

-e: extended format

-p: displays related processes and PID

-r: displays the kernel routing table

-I INT: displays statistics for the specified interface

=

2-1. Ip command

Function: configure the interface status, network parameters and routing entries of the local machine

Format: ip [OPTIONS] OBJECT {COMMAND | help}

When OBJECT is link, it is used to configure the native layer 2 link attribute configuration.

The corresponding COMMAND is:

Ip link set DEVICE {up | down | arp {on | off}: sets the interface status of layer 2 link

Ip link show [DEVICE]: view device properties

When OBJECT is address, it is used to set the native IP address

The corresponding COMMAND is:

Ip addr {add | del} IFADDR dev STRING: adds or removes an IP address from a specified network interface

Ip addr {show | flush} [dev STRING]: view or clear the IP address of the specified device

Add IP/MASK: adding addresses to Devic

Delete IP: delete the address of the device configuration

Flush: clears the configuration in the specified device

Show: viewing IP address configuration

Add the specified IP address through the add command

Specify all IP addresses of the network interface through the flush case

Used to set native routing entries when OBJECT is route

The corresponding COMMAND is:

Ip route {list | flush} SELECTOR: view or clear route entries

Ip route {add | del | change | append | replace | monitor} ROUTE: modify route entry

Add a routing entry through the add command

Modify route entries through the change command

2-2. Ss command

Function: specify an option to display the network parameters of this machine

# ss command has the same effect as netstat command, but it is more efficient. It is recommended to use ss command when the system is busy.

Format: ss [options]

Common options:

-n: display IP and port in numbers

-t: show tcp connection

-u: show udp connection

-l: Port in listening state

-a: all statu

-e: extended format

-p: displays related processes and PID

-r: displays the kernel routing table

-I INT: displays statistics for the specified interface

=

3-1. Nmcli command

Nmcli command is a command line tool to manage NetworkManager in RHEL7. Nmcli is a powerful and flexible command, but it is also very complex. Here is only a brief introduction to nmcli's connection and device objects.

Function: used to create, display, edit, delete, activate and close network connections

Format: nmcli [OPTIONS] OBJECT {COMMAND | help}

# nmcli supports Tab completion function for OBJECT and COMMAND input, which is more user-friendly, and there are corresponding help options in all levels of OBJECT, which brings great convenience in use.

When OBJECT is connection

Corresponding COMMAND: = {show | up | down | add | edit | modify | delete | reload | load}

It mainly realizes the operation of viewing and managing the connection status of the local network.

Realize the management of local network connection through connection

Multiple parameters of a network connection can be modified through the modify subcommand

When OBJECT is device

Corresponding COMMAND: = {status | show | connect | disconnect | delete | wifi | wimax}

Used to view and manage local network interface devices

You can view the detailed configuration information of the network interface through the show subcommand

=

4. Modify network parameters through a configuration file

4-1. IP address profile: / etc/sysconfig/network-scripts/ifcfg-INT

Field explanation:

# cat ifcfg-eth0

DEVICE= specifies the device name

BOOTPROTO= specifies how to obtain the IP address: dhcp or static

HWADDR= specifies the MAC address of hardware network card

NM_CONTROLLED= NM stands for NetworkManager script to replace the network protocol

PEERDNS= indicates whether the DNS received through the server is overwritten in the DNS configuration file if the IP address is obtained through dhcp

ONBOOT= specifies whether to boot the network card device automatically.

TYPE= displays the network interface type

UUID= specifies the UUID of the device

Whether IPV6INIT= enables the IPv6 feature

USERCTL= specifies whether an ordinary user controls the device

The following fields need to be configured for static IP addresses:

IPADDR= specifies the IP address

NETMASK= subnet mask

GATEWAY= default Gateway

DNS#= DNS server address, which can be configured with 3 DNS server addresses at the same time, with priority over the DNS configuration in / etc/resilov.conf

4-2. Routing profile: / etc/sysconfig/network-scripts/route-INT

# configuration files need to be created manually

file format

1. Single statement format

TARGET via GW

EX: 192.168.50.128/28 via 10.10.10.11

two。 Define a route every three lines

ADDRESS#=TARGET

NETMASK#=mask

GATEWAY#=GW

EX:

ADDRESS0=192.168.50.128

NETMASK0=255.255.255.224

GATEWAY0=10.10.10.11

# only one format can be used in the same file

4-3. DNS configuration file: / etc/resolove.conf

Specify the DNS server through nameserver DNS_IP

My level is limited, if there is any improper understanding, please correct me, thank you very much!

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

Network Security

Wechat

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

12
Report