UGH 主机路由
UG 网关路由
[root@server0 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.0.254 0.0.0.0 UG 1024 0 0 eth0 #网关路由
172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 #一般路由
172.25.253.254 172.25.0.254 255.255.255.255 UGH 1 0 0 eth0 #主机路由
查看网络IP:
查看所有的网卡的信息:
[root@desktop0 ~]# ip addr show eth0 #包含没有启动的网络接口
2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000
link/ether 52:54:00:00:00:0a brd ff:ff:ff:ff:ff:ff #二层MAC地址,和广播地址
inet 172.25.0.10/24 brd 172.25.0.255 scope global dynamic eth0 #三层IP地址和广播地址
valid_lft 20641sec preferred_lft 20641sec
inet6 fe80::5054:ff:fe00:a/64 scope link
valid_lft forever preferred_lft forever
[root@desktop0 ~]# ip -s link show eth0 #查看数据包的数量
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:00:00:0a brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
5834213 62258 0 0 0 0
TX: bytes packets errors dropped carrier collsns
6613811 59050 0 0 0 0
[root@desktop0 ~]# ip route #查看本机的路由
default via 172.25.0.254 dev eth0 pro tostatic metric 1024
172.25.0.0/24 dev eth0 proto kernel scope link src 172.25.0.10
172.25.253.254 via 172.25.0.254 deveth0 proto static metric 1
[root@desktop0 ~]# ping -c3 172.25.0.11 #IPV4
PING 172.25.0.11 (172.25.0.11) 56(84) bytesof data.
64 bytes from 172.25.0.11: icmp_seq=1ttl=64 time=1.60 ms
[root@desktop0 ~]# ping6 -c3 172.25.0.11 #ipv6
[root@desktop0 ~]# traceroute 172.25.0.11 #跟踪路由
traceroute to 172.25.0.11 (172.25.0.11), 30hops max, 60 byte p ackets
1 server0.example.com (172.25.0.11) 6.408 ms !X 5.818 ms !X 5.514 ms !X
[root@desktop0 ~]# tracepath 172.25.0.11
1: server0.example.com 1.059ms !H
Resume: pmtu 65535
SS 查看系统进程开放的端口:
[root@desktop0 ~]# ss -antulp | grep chrony
tcp UNCONN 0 0 *:123 *:* users:(("chronyd",26015,1))
tcp UNCONN 0 0 127.0.0.1:323 *:* users:(("chronyd",26015,3))
tcp UNCONN 0 0 :::123 :::* users:(("chronyd",26015,2))
tcp UNCONN 0 0 ::1:323 :::* users:(("chronyd",26015,5))
参数详解:
a 所有的
n 不解析名字
T tcp
u utp
l protocol
p process
查看端口号对应的进程:
[root@desktop0 ~]# lsof-i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 23647 root 3u IPv4 8114883 0t0 TCP desktop0.example.com:ssh->172.25.0.250:49092 (ESTABLISHED)
sshd 31621 root 3u IPv4 75102 0t0 TCP *:ssh (LISTEN)
sshd 31621 root 4u IPv6 75104 0t0 TCP *:ssh (LISTEN)
nmcli 管理系统网络
配置文件位置:
[root@desktop0~]# cd /etc/sysconfig/network-scripts/
[root@desktop0 network-scripts]# ls
ifcfg-eth0 ifdown-isdn ifdown-tunnel ifup-isdn ifup-Team
ifcfg-lo ifdown-post ifup ifup-plip ifup-TeamPort
ifdown
[root@desktop0 network-scripts]# catifcfg-eth0
DEVICE=eth0 #设备名称
BOOTPROTO=dhcp #通过DHCP协议获取IP
ONBOOT=yes #开机自动启动
TYPE=Ethernet #类型
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
PERSISTENT_DHCLIENT=1
添加连接名:
[root@desktop0 network-scripts]# nmcliconnection add con-name Home ifname eth0 type ethernet
Connection 'Home'(024d5e7e-30a9-44dd-a1c7-e26285a9583f) successfully added.
[root@desktop0 network-scripts]# nmcliconnection
NAME UUID TYPE DEVICE
Home 024d5e7e-30a9-44dd-a1c7-e26285a9583f 802-3-ethernet -- #没有生效
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0 #生效了
查看已创建的连接名详情:
[root@desktop0network-scripts]# nmcli connection show Home
connection.id: Home
connection.uuid: 024d5e7e-30a9-44dd-a1c7-e26285a9583f
connection.interface-name: eth0
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.timestamp: 0
connection.read-only: no
connection.permissions:
[root@desktop0 network-scripts]# nmcli connection up Home #激活连接名
Connection successfully activated (D-Busactive path: /org/freedesktop/NetworkManager/ActiveConnection/1)
修改连接:
[root@desktop0 network-scripts]# nmcliconnection modifycompany ipv4.addresses "172.25.0.10/24 172.25.0.254" ipv4.methodmanual ipv4.dns "172.25.254.254"
[root@desktop0 network-scripts]# nmcliconnection modify company connection.autoconnect yes #配置是否开机自动连接
如果有几个连接都有connection.autoconnect yes 参数, 则原来那个连接是用那个配置文件,重启后就用那个连接配置文件
查看系统连接的设备:
[root@desktop0 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected System eth0
lo loopback unmanaged --
[root@desktop0 ~]# nmcli device status eth0
Unknown parameter: eth0
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected System eth0
lo loopback unmanaged --
删除一个连接:
[root@desktop0 ~]# nmcli connection deleteHome
[root@desktop0 ~]# nmcli connection
NAME UUID TYPE DEVICE
company 99cc70ec-b9d5-48b8-89fc-cc7bc958cf54 802-3-ethernet --
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
如果手动编程/etc/sysconfig/network-scripts/下面的配置文件,修改完成后,在nmcli里看不了
需要通过nmcli connection reload 来重新加载配置文件
图形界面配置IP地址:
[root@desktop0network-scripts]# nm-connection-editor
修改完成后重新加载配置文件:
Nmcli connection up home
添加多个IP地址:
[root@desktop0 ~]# nmcli connection modify company +ipv4.addresses "172.25.0.102/24"
Examples:
nmcli con mod home-wifi wifi.ssid rakosnicek
nmcli con mod em1-1 ipv4.method manual ipv4.addr"192.168.1.2/24, 10.10.1.5/8"
nmcli con mod em1-1 +ipv4.dns 8.8.4.4
nmcli con mod em1-1 -ipv4.dns 1
nmcli con mod em1-1 -ipv6.addr "abbe::cafe/56"
nmcli con mod bond0 +bond.options mii=500
nmcli con mod bond0 -bond.options downdelay
删除一个IP地址:
[root@desktop0 ~]# nmcli connection modify company -ipv4.addresses "172.25.0.102/24"
Nmcli dev status
Nmcli con up id
Nmcli dev dis <DEV> 相当于拔掉网线
Nmcli net off 关闭网络接口