网络管理
获取ip地址
ip a
[root@server1 ~]
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:76:f9:7d brd ff:ff:ff:ff:ff:ff
inet 192.168.226.10/24 brd 192.168.226.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::1b78:bfb3:4567:b45c/64 scope link noprefixroute
valid_lft forever preferred_lft forever
参数解析:
lo(loop,循环):表示回环网卡,只有一个固定的IP地址,127.0.0.1代表本机
ens33:默认网卡,ip地址为192.168.226.10,可以用于远程连接
192.168.226.255 :广播地址
ifconfig
[root@server1 ~]
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.226.10 netmask 255.255.255.0 broadcast 192.168.226.255
inet6 fe80::1b78:bfb3:4567:b45c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:13:10:cf txqueuelen 1000 (Ethernet)
RX packets 26291 bytes 34566058 (32.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9118 bytes 715523 (698.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 6 bytes 504 (504.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6 bytes 504 (504.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
网卡配置文件
- /etc/sysconfig/network-scripts/ifcfg-ens33
[root@server1 ~]
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="79065771-0af6-41b9-9112-1dd5b373f8ed"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.226.10
GATEWAY=192.168.226.2
NETMASK=255.255.255.0
DNS1=114.114.114.114
参数解析:
TYPE :网络类型,Ethernet以太网
BOOTPROTO:IP的获取方式,dhcp代表自动获取,static/none代表手工设置
NAME :网卡的名称(名字),ens33
UUID :代表网卡的UUID编号,编号唯一
DEVICE :设备名称
ONBOOT :代表网卡是否随计算机开启自启,默认yes
IPADDR :手工配置地址
GATEWAY :网关
NETMASK :子网掩码,默认255.255.255.0
DNS :域名解析服务器地址,默认114.114.114.114
systemctl
systemctl = system control
- systemctl status network 查询网络状态
[root@server1 ~]
● network.service - LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
Active: active (exited) since 五 2021-08-13 14:59:42 CST; 2h 4min ago
Docs: man:systemd-sysv-generator(8)
8月 13 14:59:42 server1 systemd[1]: Starting LSB: Bring up/down networking...
8月 13 14:59:42 server1 network[723]: 正在打开环回接口: [ 确定 ]
8月 13 14:59:42 server1 network[723]: 正在打开接口 ens33: [ 确定 ]
8月 13 14:59:42 server1 systemd[1]: Started LSB: Bring up/down networking.
参数解析:
Active : active(正常)或 inactive(dead,网络没有连接)
- systemctl start network 启动
- systemctl stop network 停止
- systemctl restart network 重启
ifconfig网络管理
该命令只能root去操作
- ifconfig 查看所有网络接口信息
- ifconfig ens33 查看ens33接口信息
[root@server1 ~]
[root@server1 ~]
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.226.10 netmask 255.255.255.0 broadcast 192.168.226.255
inet6 fe80::1b78:bfb3:4567:b45c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:76:f9:7d txqueuelen 1000 (Ethernet)
RX packets 24820 bytes 34446076 (32.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8094 bytes 615735 (601.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
参数解析:
inet 192.168.226.10 :代表ens33网卡的IP地址,可以用于远程连接
netmask 255.255.255.0:子网掩码,一般为255.255.255.0
roadcast 192.168.226.255 :广播地址
RX(TX):代表网卡收(发)的流量数据包大小
- ifconfig ens33 up 开启ens33网卡
- ifconfig ens33 down 关闭ens33网卡
[root@server1 ~]
[root@server1 ~]
[root@server1 ~]
[root@server1 ~]
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.226.10 netmask 255.255.255.0 broadcast 192.168.226.255
inet6 fe80::1b78:bfb3:4567:b45c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:76:f9:7d txqueuelen 1000 (Ethernet)
RX packets 25485 bytes 34500359 (32.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8576 bytes 662334 (646.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.226.11 netmask 255.255.255.0 broadcast 192.168.226.255
ether 00:0c:29:76:f9:7d txqueuelen 1000 (Ethernet)
ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.226.12 netmask 255.255.255.0 broadcast 192.168.226.255
ether 00:0c:29:76:f9:7d txqueuelen 1000 (Ethernet)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@server1 ~]
[root@server1 ~]
[root@server1 ~]
[root@server1 ~]
ether 00:0c:29:13:10:cf txqueuelen 1000 (Ethernet)
ether 00:0c:29:13:10:cf txqueuelen 1000 (Ethernet)
ether 00:0c:29:13:10:cf txqueuelen 1000 (Ethernet)
ifconfig只是临时修改网络配置,想要永久修改,需要修改网卡的配置文件/etc/sysconfig/network-scripts/ifcfg-ens33
route静态路由
用法
[root@server1 ~]
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.226.2 0.0.0.0 UG 100 0 0 ens33
192.168.226.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
参数解析:
Destination:表示网络号
Gateway:网关,显示0.0.0.0表示该路由是从本机发出的
Genmask:子网掩码
Flags:路由标记
U:up运行
G:表示其是网关
H:表示网关是一个主机
!:表示当前路由已被禁止
[root@server1 ~]
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.226.2 0.0.0.0 UG 100 0 0 ens33
192.168.226.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@server1 ~]
[root@server1 ~]
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.226.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@server1 ~]
[root@server1 ~]
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.226.2 0.0.0.0 UG 0 0 0 ens33
192.168.226.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
ip命令
ip 选项 对象 操作
对象:
link:网络设备
addr(ess):定义ipv4,ipv6的地址
neighbour:查看ARP缓存,检查MAC地址
route:路由表
maddress:多播地址
tunel:ip通道
操作:
增:add
删:del
改:set
查:show
选项:
-s:显示详细信息
[root@server1 ~]
[root@server1 ~]
[root@server1 ~]
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:13:10:cf brd ff:ff:ff:ff:ff:ff
[root@server1 ~]
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:13:10:cf brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
34579077 26461 0 0 0 0
TX: bytes packets errors dropped carrier collsns
727217 9228 0 0 0 0
[root@server1 ~]
[root@server1 ~]
[root@server1 ~]
[root@server1 ~]
ip a = ip addr show
netstat网络端口
[root@server1 ~]
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.226.10:22 192.168.226.1:61947
[root@server1 ~]
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11336/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 893/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1077/master
tcp6 0 0 :::22 :::* LISTEN 893/sshd
[root@server1 ~]
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
ens33 1500 26935 0 0 0 9575 0 0 0 BMRU
lo 65536 16 0 0 0 16 0 0 0 LRU
选项说明:
-a:显示所有的socket信息
-n:不进行dns解析:显示数字地址,而非主机名
-t:tcp
-u:udp
-l:只显示是正在监听的socket
-p:显示进程号和进程名
-i:显示所有网络接口
字段解析:
Proto:socket使用的协议
Recv-Q:连接该socket的用户,为拷贝的字节数
Local Address :本地地址及端口号
Foreign Address:远程主机地址及端口号
State:运行状态,listen表监听中
PID/Program name:进程号和进程名
Iface:设备名
MTU:最大传输单元,单位为字节数
RX-OK(RX-ERR):正确(错误)接收了多少数据包
RX-DRP:接送丢弃了多少数据包
RX-OVR:接送遗失了多少数据包
TX-OK(TX-ERR):正确(错误)发送了多少数据包
TX-DRP:发送丢弃了多少数据包
TX-OVR:发送遗失了多少数据包
Flg:标记
L:回环地址
R:正在运行中
U:接口正在处于活动的状态
B:广播地址
M:接收所有的数据包
O:禁止arp
P:端对端的连接
ss命令用法以及参数几乎和netstat等同!!!
|