In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Network management can be divided into two ways: command line implementation and configuration file. But most of the networks configured by command-line commands are temporary and effective immediately, while the networks configured through configuration files are permanently valid (of course, accidents can be ignored), but not immediately, because the function of network management is provided by the kernel, and the network configured through commands can be directly accepted by the kernel, and we know that everything is a file in Linux, and so is the network. It is only permanently valid if you write to a file related to the network configuration, but these configuration files are not immediately recognized by the kernel, so they will not take effect immediately, so you have to let the kernel reread the configuration file.
Let's start with the command line command configuration network.
Ifcfg family:
Ifconfig: used to display and configure network interface cards
Ifconfig or ifconfig-a displays all network interface information. The difference is that ifconfig can only display network card information that has been turned on, while ifconfig-a can really display all network card information, including those that are open and those that are not.
Ifconfig network card name: displays only the information of the specified network interface card
Ifconfig Nic name ip address / mask (this is the easiest way)
[root@localhost] # ifconfig eth2eth2: flags=4163 mtu 1500 inet 172.168.0.1 netmask 255.255.0.0 broadcast 172.168.255.255 ether 00:0c:29:f8:b5:f8 txqueuelen 1000 (Ethernet) RX packets 25 bytes 3168 (KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10 bytes 1308 (1.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] #
Ifconfig network card name down or up: close the specified network card; enable the specified network card
[root@localhost ~] # ifconfig eth2 down [root@localhost ~] # ifconfig eth2eth2: flags=4098 mtu 1500 inet 172.168.0.1 netmask 255.255.0.0 broadcast 172.168.255.255 ether 00:0c:29:f8:b5:f8 txqueuelen 1000 (Ethernet) RX packets 28 bytes 3348 (3.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10 bytes 1308 (1.2 KiB) TX errors 0 Dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] # although it still shows an address But the UP logo is gone.
Ifconfig Nic name [-] feature: turn some features on and off, such as turning on and off hybrid mode
[root@localhost ~] # ifconfig eth2 promisc [root@localhost ~] # ifconfig eth2eth2: flags=4354 mtu 1500 ether 00:0c:29:f8:b5:f8 txqueuelen 1000 (Ethernet) RX packets 28 bytes 3348 (3.2KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10 bytes 1308 (1.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] # ifconfig eth2-promisc [root@localhost ~] # ifconfig Eth2eth2: flags=4098 mtu 1500 ether 00:0c:29:f8:b5:f8 txqueuelen 1000 (Ethernet) RX packets 28 bytes 3348 (3.2KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10 bytes 1308 (1.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] #
Route: displaying and configuring routed
Route-n: do not display the routing table in an inverse way (recommended)
[root@localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.1.1 0.0.0.0 UG 1000 eno16777728192.168.1.0 0.0.0.0 255.255.255.0 U 10000 eno16777728 [root@localhost ~] # where Destination A value of 0.0.0.0 indicates a native default route The destination network with a Gateway of 0.0.0.0 is the network on which the machine is located, so no routing is required.
Route add / Mask gw startled ip [dev] [Nic]
[root@localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.1.1 0.0.0.0 UG 1000 eno167777280.0.0.0 192.168.1.1 0.0.0.0 UG 101 00 eth2192.168.1.0 0 .0.0.0 255.255.255.0 U 10000 eno16777728192.168.1.0 0.0.0.0 255.255.255.0 U 101 00 eth2 [root@localhost ~] # route add-net 172.16.0.0amp16 gw 192.168.1.1 [root@localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.1.1 0.0.0.0 UG 100 00 eno167777280.0.0.0 192.168.1.1 0.0.0.0 UG 101 00 eth2172.16.0.0 192.168.1.1 255.255.0.0 UG 00 0 eno16777728192.168.1.0 0.0.0.0 255.255.255.0 U 100 00 eno16777728192.168.1.0 0.0.0.0 255.255.255.0 U 101 00 eth2 [root@localhost ~] # it should be noted that the next hop address (gateway) must be in the network of any local network card Because if even the gateway is not in the local network, how can we talk about routing? Then you can know the network of any local network card through the Gateway of 0.0.0.0.
Route add default dev network cards: adding default rout
[root@localhost ~] # route add default gw 172.16.0.1 dev eth2 [root@localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 172.16.0.1 0.0.0.0 UG 000 eth20.0.0.0 0.0.0.0 0.0.0.0 U 00 0 eth20.0.0.0 192.168.1.1 0.0.0.0 UG 100 00 eno167777280.0.0.0 192.168.1.1 0.0.0.0 UG 101 00 eth2172.16.0.0 192.168.1.1 255.255.0.0 UG 00 0 eno16777728192.168.1.0 0.0.0.0 255.255.255.0 U 100 00 eno16777728192.168.1.0 0.0.0.0 255.255.255.0 U 101 00 eth2
Route del-net routing / masking dev network card
[root@localhost ~] # route del-net 0.0.0.0 eno167777280.0.0.0 0 dev eth2 [root@localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.1.1 0.0.0.0 UG 10000 eno167777280.0.0.0 192.168.1.1 0.0.0.0.0 UG 101 00 eth2172.16.0.0 192.168.1.1 255.255.0.0 UG 00 0 eno16777728192.168.1.0 0.0.0.0 255.255.255.0 U 100 00 eno16777728192.168.1.0 0.0.0.0 255.255.255.0 U 101 0 eth2 [root@localhost ~] #
Netstat: viewing network status information
Common options are:
-t: displays the tcp transport protocol's
-u: displays the udp transport protocol's
-n: does not display in an inverse way (that is, digital format)
-l: in the listening state
-p: show related processes and pid
-e: extended format display
-a: show all statu
[root@localhost ~] # netstat-tunlpActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0 tunlpActive Internet connections 22 0.0.0.0 Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp * LISTEN 1324/sshd tcp 0 0 127.0.1 15 0 .0.0: * LISTEN 1425/master tcp6 00: 22:: * LISTEN 1324/sshd tcp6 00:: 1:25:: * LISTEN 1425/master omitted. Other ways should be combined by yourself, such as tan,uan,tnl,unl.
The ifup and ifdown commands open and close the Nic by reading the file / etc/sysconfig/network-scripts/ifcfg- Nic name. If not, an error will be reported.
Iproute family:
Ip link: display and manage network card information
Ip link show (list): displays network card information
[root@localhost ~] # ip link show1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 0000 qdisc pfifo_fast state UP mode DEFAULT qlen 0000 eth2: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:f8 : b5:f8 brd ff:ff:ff:ff:ff:ff
Ip link set:
Ip link set [dev] Network Card up (down): turns the network card on (off)
[root@localhost ~] # ip link set eth2 down [root@localhost ~] # ip link show1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 0000 link/ether 00:0c:29:f8:b5:ee brd ff:ff:ff:ff:ff:ff3: eth2: mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff [root@localhost ~] #
Ip link set [dev] Nic mtu #: set mtu size
Ip link set [dev] Network name NAME: rename
[root@localhost ~] # ip link set eth2 down [root@localhost ~] # ip link set eth2 name eth0 [root@localhost ~] # ip link show1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 1000 link/ether 00:0c:29:f8:b5:ee brd ff:ff:ff:ff:ff:ff3: eth0 : mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff [root@localhost ~] #
Ip link set [dev] Network Card multicast on (off): enable (disable) Multicast
Ip netns: manage network namespaces
Ip netns add NAME: adding cyberspace
Ip netns list: lists cyberspace names
Ip netns del NAME: deleting cyberspace
Ip netns exec NAME COMMAND: executes commands in the specified net space
[root@localhost ~] # ip link set eth2 down [root@localhost ~] # ip link set eth2 name eth0 [root@localhost ~] # ip link show1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 1000 link/ether 00:0c:29:f8:b5:ee brd ff:ff:ff:ff:ff:ff3: eth0 Mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff [root@localhost ~] # ip netns add mynet [root@localhost ~] # ip netns list mynet [root@localhost ~] # ip link set eth0 netns mynet [root@localhost ~] # ip link show1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 0000 brd 00:00:00 Eno16777728: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:f8:b5:ee brd ff:ff:ff:ff:ff:ff [root@localhost ~] # the network card placed in the space cannot be displayed directly [root@localhost ~] # ip netns exec mynet ip link show1: lo: mtu 65536 qdisc noop state DOWN mode DEFAULT link/loopback 0000 brd 00:00:00 Eth0: mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff [root@localhost] # only in this way can it be displayed But take a look at [root@localhost ~] # ip netns del mynet [root@localhost ~] # ip netns list [root@localhost ~] # ip link show1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 0000VO 0000VlV 0000VO 00 brd 0000VOV 0000VIE0000VOL00VO: eno16777728: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:f8:b5:ee brd ff:ff:ff:ff:ff:ff3 Eno33554968: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff [root@localhost ~] # because I renamed the second network card earlier in order to demonstrate Put it into cyberspace and then come out and restore it.
Ip addr; displays and sets network addresses
Ip addr add ip/ mask dev network card dev cannot be saved here
Ip addr del ip/ masked dev network card
[root@localhost ~] # ip addr add 10.0.0.1 ether 00:0c:29:f8:b5:f8 txqueuelen 8 dev eth2 [root@localhost ~] # ifconfig eth2eth2: flags=4163 mtu 1500 inet 10.0.0.1 netmask 255.0.0.0 broadcast 0.0.0.0 ether 00:0c:29:f8:b5:f8 txqueuelen 1000 (Ethernet) RX packets 197 bytes 18250 (17.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 48 bytes 5004 (4 .8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] #
Ip addr can add multiple addresses to a network card, but only those on the same network segment can be divided into primary and secondary.
[root@localhost ~] # ip addr add 172.16.0.2 ip addr show 16 dev eth2 [root@localhost ~] # ip addr show 3: eth2: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff inet 10.0.0.1 qdisc pfifo_fast state UP qlen 8 scope global eth2 valid_lft forever preferred_lft forever inet 172.16.0.2 scope global eth2 valid_lft forever preferred_lft forever inet 16 scope global eth2 valid_lft forever preferred _ lft forever inet 10.0.0.2 broadcast 8 scope global secondary eth2 valid_lft forever preferred_lft forever [root@localhost ~] # and ifconfig will only show the source address [root@localhost ~] # ifconfig eth2eth2: flags=4163 mtu 1500 inet 10.0.0.1 netmask 255.0.0.0 broadcast 0.0.0.0 ether 00:0c:29:f8:b5:f8 txqueuelen 1000 (Ethernet) RX packets 211 bytes 19090 (18. 6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 48 bytes 5004 (4.8KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
If you want ifconfig to display, you can only add an alias.
[root@localhost ~] # ip addr add 192.19.0.1 dev eth2 lable eth2:0Error 24 dev eth2 lable eth2:0Error: either "local" is duplicate, or "lable" is a garbage. [root@localhost ~] # ip addr add 172.16.0.3 dev eth2 lable eth2:0Error 16 dev eth2 lable eth2:0Error: either "local" is duplicate, or "lable" is a garbage. [root@localhost ~] # ip addr add 172.16.0.3 lable 16 dev eth2 label eth2:0 [root@localhost ~] # ifconfig eth2:0 Ip addr show eth2eth2:0: flags=4163 mtu 1500 inet 172.16.0.3 netmask 255.255.0.0 broadcast 0.0.0.0 ether 00:0c:29:f8:b5:f8 txqueuelen 1000 (Ethernet) 3: eth2: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff inet 10.0.0.1 scope global eth2 valid_lft Forever preferred_lft forever inet 172.16.0.2 forever preferred_lft forever inet 16 scope global eth2 valid_lft forever preferred_lft forever inet 10.0.0.2 forever preferred_lft forever inet 8 scope global secondary eth2 valid_lft forever preferred_lft forever inet 172.16.0.3 root@localhost 16 scope global secondary eth2:0 valid_lft forever preferred_lft forever [root@localhost ~] # is to add the label network card when adding the address: number (0-9)
Ip addr flush dev network card: clear the ip address of all specified network cards
[root@localhost ~] # ip addr flush dev eth2 [root@localhost ~] # ip addr show eth23: eth2: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff [root@localhost ~] #
Ip route: managing rout
Ip route show (list): displays routing information
Ip route add Network / Mask via next Hop address [dev] Nic [src Source ip address]
[root@localhost ~] # ip addr add 172.16.0.1 qdisc pfifo_fast state UP qlen 16 dev eth2 [root@localhost] # ip addr add 172.16.0.2 ip addr list eth23 16 dev eth2 [root@localhost ~] # ip addr list eth23: eth2: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:f8:b5:f8 brd ff:ff:ff:ff:ff:ff inet 172.16.0.1 scope global eth2 valid_lft forever preferred_lft forever Inet 172.16.0.2 scope global secondary eth2 valid_lft forever preferred_lft forever 16 scope global secondary eth2 valid_lft forever preferred_lft forever [root@localhost ~] # ip route showdefault via 192.168.1.1 dev eno16777728 proto static metric 100 172.16.0.0 dev eth2 proto kernel scope link src 16 via 192.168.1.1 dev eno16777728 172.16.0.0 dev eth2 proto kernel scope link src 172.16.0.1 192.168.1.0 metric 24 dev eno16777728 proto kernel scope link src 192.168.1.107 metric 100 [root@localhost ~] # ip route add 10.0.0.0 ip route add 8 via 172.16.10.1 dev eth2 src 172.16.0.1 [root@localhost ~] # ip route showdefault via 192.168.1.1 dev eno16777728 proto static metric 100 10.0.0.0 dev eth2 src 8 via 172.16.10.1 dev eth2 src 172.16.0.1 172.16.0.0 dev eth2 src 16 via 192.168.1.1 dev eno16777728 172.16.0.0 dev eth2 src .16.0.1 192.168.1.0 bind 24 dev eno16777728 proto kernel scope link src 192.168.1.107 metric 100 [root@localhost ~] # you can specify the source address when there are many network card addresses
Ip route delete Network / Mask: delete specified rout
[root@localhost ~] # ip route del 10.0.0.0 metric 8 [root@localhost ~] # ip route showdefault via 192.168.1.1 dev eno16777728 proto static metric 100 172.16.0.0 dev eth2 proto kernel scope link src 16 via 192.168.1.1 dev eno16777728 172.16.0.0 dev eth2 proto kernel scope link src 172.16.0.1 192.168.1.0 metric 24 root@localhost ~
Ip route flush Network / Mask: clears all routes in the specified network
Ss command: similar to netstat, but more powerful
In addition to the-tjinghujinghujinghujinghujinghujinghe, there are also
-m: displays memory usage
-o: display timer information
It can also display the connection status of the execution.
State:
LISTEN
ESTABLISHMENT
FIN_WAIT1:
FIN_WAIT2
SYN_SENT
SYN_RECV
CLOSED
Port:
Dport
Sport
Configuration files configure the network:
/ etc/sysconfig/network-scripts/ifcfg- network card name: this file can configure a large amount of network interface information.
DEVICE= specifies that the device should be the same as the network card name
ONBOOT: [yes | no]; whether to boot or not
IPV6INIT: [yes | no]: whether to initialize IPV6
BOOTPROTO: four (dhcp,bootp,static,none)
UUID: the UUID number of this device
TYPE: network type (e.g. Ehernet,Bridge)
IPADDR:ip address
DNS1: the first dns
DNS2: standby dns
NETMASK (PREFIX); mask
GATEWAY: default gateway
USERCTL: whether to allow ordinary users to control this device
PEERDNS: whether to allow dns assigned by dhcp server to override manually specified dns when BOOTPROTO is dhcp. Default is to allow.
NM_CONTROLLED: whether to enable NetworkManager to manage the network
HWADDR:MAC address
If you want to specify a route other than the default route, configure it in the file / etc/sysconfig/network-scripts/route- Nic name.
There are two ways, here I only write the simplest way
Network / Mask length via ip
One route at a time
The DNS configuration file is located at: / etc/resolv.conf:
Nameserver:DNS
One by one.
Set priority DNS mapping at / etc/hosts
Ip domain name alias 1 alias 2..
Hostname setting:
Hostname: display hostname
Hostname HOSTNAME: set the hostname, but the restart will fail
Hostnamectl set-hostname HOSTNAME: permanently valid
/ etc/sysconfig/network configuration file:
Hostname=HOSTNAME
Note: profile configuration must be reread to be valid
There are also some tools: setup,nmtui graphical interface to set up the network, but also permanently effective, open will!
And nmcli and ifconfig are very similar. We won't demonstrate them one by one here.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.