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

CentOS7 network management and configuration

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Network management under linux can probably be implemented in two ways: commands and configuration files, most of which can only take effect at a single time after execution, while configuration files can be permanently effective, which can be managed in different ways according to different scenarios.

Ifconfig:

Ifconfig [- a] interfer to view the current system active API

-a: displays all interfaces, including inactivity.

[root@bogon yum.repos.d] # ifconfigeno16777736: flags=4163 mtu 1500 inet 192.168.67.128 netmask 255.255.255.0 broadcast 192.168.67.255 inet6 fe80::20c:29ff:fe74:803f prefixlen 64 scopeid 0x20 ether 00:0c:29:74:80:3f txqueuelen 1000 (Ethernet) RX packets 7404 bytes 6161993 (5.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1556 bytes 130066 .0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Eno16777736: name of the network card

Flags: flag bit

UP: Nic enabled statu

BROADCAST: support for broadcast

RUNNING: running

MULTICAST: supports Multicast

Mtu: maximum transport single source. Default is 1500.

Init: Ipv4 address

Init6: Ipv6 address

Txqueuelen: transmission queue length

RX packets: number of messages received

RX errors: the number of messages with errors in acceptance

Dropped: the number of packets lost

Overruns: the number of messages overflowed

Frame: Fram

Modify the network configuration:

[root@bogon ~] # ifconfig eno33554984 192.168.77.111 gamma 24 up [root@bogon ~] # ifconfig eno33554984 eno33554984: flags=4163 mtu 1500 inet6 fe80::20c:29ff:fe74:8049 prefixlen 64 scopeid 0x20 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 TX packets 0 bytes 17988 (17.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0c ollisions 0

Options:

[-] promisc on / off hybrid mode

[-] allmulti starts / shuts down multicast

Up

Down

Route:

Route View Route

[root@bogon ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault bogon 0.0.0.0 UG 10000 eno16777736192.168.67.0 0.0.0.0 255.255.255.0 U 10000 eno16777736

Route-n

[root@bogon ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.67.2 0.0.0.0 UG 10000 eno16777736192.168.67.0 0.0.0.0 255.255.255.0 U 10000 eno16777736

Route add [- net |-host] target [gw GW] [dev]

-net: host routing host, destination address is a single IP

-host: network path net, destination address is IP network

[root@bogon ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault bogon 0.0.0.0 UG 1000 eno16777736192.168.67.0 0.0.0.0 255.255.255.0 U 10000 eno16777736 [root@bogon ~] # route add-net 12.0.0.0 net 8 gw 192. 168.67.2 dev eno16777736 [root@bogon ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault bogon 0.0.0.0 UG 1000 eno1677773612.0.0.0 bogon 255.0.0.0 UG 00 0 eno16777736192.168.67.0 0.0.0.0 255.255.255.0 U 1000 eno16777736 [root@bogon ~] # route add-net 13.0.0.0 netmask 255.0.0.0 gw 192.168.67.4 dev eno16777736 [root@bogon ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault bogon 0.0.0.0 UG 10000 eno1677773612.0.0 . 0 bogon 255.0.0.0 UG 00 0 eno1677773613.0.0.0 bogon 255.0.0.0 UG 00 0 eno16777736192.168.67.0 0.0.0.0 255.255.255.0 U 100 00 eno16777736

Route del [- net |-host] TARGET gw GATEWAY [dev IFNAME]

[root@bogon ~] # route del-net 13.0.0.0 netmask 255.0.0.0 gw 192.168.67.4 dev eno16777736 [root@bogon ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault bogon 0.0.0.0 UG 10000 eno1677773612.0.0.0 bogon 255.0.0.0 UG 00 0 eno16777736192.168.67.0 0.0.0.0 255.255.255.0 U 100 00 eno16777736

Netstat command: displays network connections, routing tables, camouflage links, and multicast membership

[root@bogon ~] # netstatActive Internet connections (wAccord o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 bogon:ssh bogon:63059 ESTABLISHEDtcp 0 52 bogon:ssh bogon:54942 ESTABLISHED

Netstat-r: show kernel routing table

Netstat-n: numeric format, does not reverse the IP address to the host name

[root@bogon] # netstat-nActive Internet connections (w servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 192.168.67.128 ESTABLISHEDtcp 22 192.168.67.1 ESTABLISHEDtcp 052 192.168.67.128 Vol 22 192.168.67.1 servers 54942

Netstat-t:TCP protocol related connections, links have their own status

[root@bogon ~] # netstat-tActive Internet connections (wstroke o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 bogon:ssh bogon:63059 ESTABLISHEDtcp 0 52 bogon:ssh bogon:54942 ESTABLISHED

Related connections of netstat-u:udp protocol

[root@bogon] # netstat-uActive Internet connections (w _ servers) Proto Recv-Q Send-Q Local Address Foreign Address State

Netstat-w:raw socket related links

Netstat-l: the link that is listening

[root@bogon yum.repos.d] # netstat-lActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:ssh 0.0.0.0 Proto Recv-Q Send-Q Local Address Foreign Address State tcp * LISTEN tcp 0 0 localhost:ipp 0.0.0.0 lActive Internet connections * LISTEN Tcp 0 0 localhost:smtp 0.0.0.0 LISTEN

Proto protocol

Recv-Q accept queue

Send-Q send queue

Netstat-a: all states (run, monitor)

Netstat-n: display IP and Port in digital format

Netstat-e: display extended format

[root@bogon ~] # netstat-eActive Internet connections (wbat o servers) Proto Recv-Q Send-Q Local Address Foreign Address State User Inode tcp 0 52 bogon:ssh bogon:56488 ESTABLISHED root

Netstat-I shows all interfaces

[root@bogon ~] # netstat-iKernel Interface tableIface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flgeno16777 1500 300 000 0 137 000 BMRU

Netstat-I

[root@bogon ~] # netstat-Ieno33554984Kernel Interface tableIface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flgeno33554 1500 00 00 140 000 BMRU

Ifup / ifdown turns on and off the network card

[root@bogon network-scripts] # ifup eno33554984Connection successfully activated (D-Bus active path: / org/freedesktop/NetworkManager/ActiveConnection/21) [root@bogon network-scripts] # ifdown eno33554984Device 'eno33554984' successfully disconnected.

Housname

CentOS6:

View hostname: hostname

Configuration hostname: hostname HOSTNAME

By modifying the configuration file configuration file: / etc/sysconfig/network HOSTNAME=

[root@localhost ~] # vim / etc/sysconfig/networkNETWORKING=yesHOSTNAME=localhost.localdomain

CentOS7:

Hostnamectl status: displays the current hostname settings:

[root@bogon ~] # hostnamectl status Static hostname: localhost.localdomainTransient hostname: bogon Icon name: computer-vm Chassis: vm Machine ID: 5428a4d5a4bb46b8a5d02ecc7d30d003 Boot ID: c86d23aa109846569cf578d31f2b25e5 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64

Hostnamectl set-hostname sets the hostname, which is valid forever

Unknown operation set-lin [root@bogon ~] # hostnamectl set-hostname lin [root@bogon ~] # hostnamectl Static hostname: lin Icon name: computer-vm Chassis: vm Machine ID: 5428a4d5a4bb46b8a5d02ecc7d30d003 Boot ID: c86d23aa109846569cf578d31f2b25e5 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64

Ip:

Ip link network device configuration

Ip link set interface down

[root@bogon ~] # ip link set eno33554984 down [root@bogon ~] # ifconfigeno16777736: flags=4163 mtu 1500 inet 192.168.67.128 netmask 255.255.255.0 broadcast 192.168.67.255 inet6 fe80::20c:29ff:fe74:803f prefixlen 64 scopeid 0x20 ether 00:0c:29:74:80:3f txqueuelen 1000 (Ethernet) RX packets 15526 bytes 1106373 (1.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 5354 bytes 933749 (911.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 0 (Local Loopback) RX packets 12 bytes 1020 (1020.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 1020 (1020.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Ip link set interface up

[root@bogon] # ifconfigeno16777736: flags=4163 mtu 1500 inet 192.168.67.128 netmask 255.255.255.0 broadcast 192.168.67.255 inet6 fe80::20c:29ff:fe74:803f prefixlen 64 scopeid 0x20 ether 00:0c:29:74:80:3f txqueuelen 1000 (Ethernet) RX packets 15568 bytes 1109751 (1.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 5378 bytes 937177 (915.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0eno33554984: flags=4163 mtu 1500 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 254bytes 43248 (42.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Ip link set interface multicast on enables Multicast

Ip link set interface multicastoff turns off Multicast

[root@bogon network-scripts] # ip link set eno33554984 multicast off [root@bogon network-scripts] # ifconfig eno33554984eno33554984: flags=67 mtu 1500 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets bytes 43248 (42.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@bogon network-scripts] # ip link set Eno33554984 multicast on [root@bogon network-scripts] # ifconfig eno33554984eno33554984: flags=4163 mtu 1500 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 254bytes 43248 (42.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Ip link set interface name NAME changes device name

[root@bogon network-scripts] # ip link set eno33554984 name eth0 [root@bogon network-scripts] # ifconfig eth0 eth0: flags=4098 mtu 1500 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets bytes 43248 (42.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Ip link set interface mtu sets MTU value. Default is 1500.

Root@bogon network-scripts] # ip link set eth0 mtu 1600 [root@bogon network-scripts] # ifconfig eth0eth0: flags=4098 mtu 1600 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets bytes 43248 (42.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Ip netns: creates the specified space

Ip netns list accumulates all netns

Ip netns add name adds the specified netns

Ip netns del name deletes the specified netns

Run commands in the netns specified by ip netns exec NAME COMMAND

[root@bogon network-scripts] # ip netns list [root@bogon network-scripts] # ip netns add test [root@bogon network-scripts] # ip netns listtest [root@bogon network-scripts] # ip link set eth0 netns test [root@bogon network-scripts] # ifconfigeno16777736: flags=4163 mtu 1500 inet 192.168.67.128 netmask 255.255.255.0 broadcast 192.168.67.255 inet6 fe80::20c:29ff:fe74:803f prefixlen 64 scopeid 0x20 ether 00:0c:29 : 74Glav 80 txqueuelen 1000 (Ethernet) RX packets 18036 bytes 1295528 (1.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6286 bytes 1033927 (1009.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 0 (Local Loopback) RX packets 12 bytes 1020 (1020.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 1020 (1020.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@bogon network-scripts] # ip netns del test [root@bogon network-scripts] # ifconfigeno16777736: flags=4163 mtu 1500 inet 192.168.67.128 netmask 255.255.255.0 broadcast 192.168.67.255 inet6 fe80::20c:29ff:fe74:803f prefixlen 64 scopeid 0x20 ether 00:0c:29:74:80:3f txqueuelen 1000 (Ethernet) RX packets 18104 bytes 1301156 (1.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6323 bytes 1038797 (1014.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0eno33554984: flags=4163 mtu 1600 inet 192.168.66.123 netmask 255.255.255.0 broadcast 192.168.66.255 inet6 fe80::20c : 29ff:fe74:8049 prefixlen 64 scopeid 0x20 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 262 bytes 43868 (42.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Ip addr: used to manage IP addresses

Ip addr add IP/MASK dev label

[root@lin ~] # ip addr add dev eth0 192.168.77.78 netmask 24 label eth0:1 [root@lin ~] # ip addr add dev eth0 192.168.77.79 ifconfigeno16777736 24 label eth0:2 [root@lin ~] # ifconfigeno16777736: flags=4163 mtu 1500 inet 192.168.67.128 netmask 255.255.255.0 broadcast 192.168.67.255 inet6 fe80::20c:29ff:fe74:803f prefixlen 64 scopeid 0x20 ether 00:0c:29:74:80 3F txqueuelen 1000 (Ethernet) RX packets 19978 bytes 1455021 (1.3 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 7267 bytes 1146820 (1.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0eth0: flags=4163 mtu 1600 inet 192.168.77.74 netmask 255.255.255.0 broadcast 0.0.0.0 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 266 bytes 44112 (43.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0eth0:1: flags=4163 mtu 1600 inet 192.168.77.78 netmask 255.255.0 broadcast 0.0.0.0 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) eth0:2: flags=4163 mtu 1600 inet 192 .168.77.79 netmask 255.255.255.0 broadcast 0.0.0.0 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet)

Ip addr delete deletion

Ip addr show displays all routing information

[root@lin ~] # ip addr delete dev eth0 192.168.77.77 ifconfig eth0eth0: flags=4163 mtu 1600 inet 192.168.77.74 netmask 255.255.255.0 broadcast 0.0.0.0 ether 00:0c:29:74:80:49 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 266 bytes 44112 (43 .0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Ip addr flush clears all

Ip route

Ip route option TPYE PREFIX via [GW] [dev IFACE] [src SOUCE]

Ip route add add Route

[root@lin ~] # ip route add 10.0.0.0 dev eno16777736 8 via 192.168.67.1 [root@lin ~] # ip route showdefault via 192.168.67.2 dev eno16777736 proto static metric 100 10.0.0.0 dev eno16777736

Ip route delete: deleting rout

[root@lin ~] # ip route del 10.0.0.0 metric 8 via 192.168.67.1 [root@lin ~] # ip route showdefault via 192.168.67.2 dev eno16777736 proto static metric 100 192.168.67.0 metric 100 192.168.67.128 metric 100 192.168.77.0 metric 192.168.77.74

Ip route get: get routing hee hee

[root@lin ~] # ip route get 192.168.67.0broadcast 192.168.67.0 dev eno16777736 src 192.168.67.128 cache

Ip route flush

Ss

Ss [options] [FILTER]

-related connections of t:TCP protocol

-u: UDP related connection

-w: links related to raw socket

-l: understanding of monitoring status

-n: numeric format

-p: related programs and their PID

-e: extended format information

-m: memory usage

[root@lin ~] # ss-tnlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *: 22 *: * LISTEN 0 128 127.0.1 tnlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 631 *: *

-o: and other information

Dport= destination Port

Sport= source port

Example:'(dport=:22 sport=:22)'

Ss-tan'(dport=:22 or sport=:22)'

Ss-tan state ESTABLISHED

Configure network properties by modifying the configuration file:

IP/NETMASK/GW/DNS:

/ etc/sysconfig/network-scripts/ifcfg-IFACE

IFACE: interface name

Configuration files related to routing:

/ etc/sysconfig/network-scripts/route-IFACE

Two configuration modes are supported, but they cannot be mixed

(1) one route entry per row

TARGET via GW

(2) there is no three lines and one route entry

ADDRESS#=TARGER

NETWORK#=MASK

GATEWAY#=NEXT

Configure the DNS server to point to:

Configuration file: / etc/resolv.conf has up to three hosts

Nameserver DNS_SERVER_IP

How to test: (host/nslookup/dig)

/ etc/hosts

The ping command in the system shows whether there is a corresponding IP and domain name in the / etc/hosts file. If not, check resolv.conf.

So when testing, skip the host file.

Dig-t A hostname FQDN (www.baidu.com)

FQDN-- > IP

Dig-x IP

IP-- > hostname

Nmcli

Device: display and network interface

Nmcli device status

Nmcli device connect

Nmcli device disconnect

Nmcli device show

Connection:

Nmcli connection show

Nmcli connection up IFACE

Nmcli connectionn down IFACE

Nmcli connectionn modify IFACE [+ | -] setting address vlue

Setting:

Ipv4.addresss

Ipv4.gateway

Ipv4.dns1

Ipv4.method configuration method

Manual static?

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