标签:功能 网络路由 替换 style ble seh source br0 ssi
iproute家族命令:
ip命令
ss命令
nmcli命令
nmtui命令
ip命令
ip [OPTION] OBJECT {COMMAND | help}
常用OBJECT:
link,addr,route,netns
注意: OBJECT可简写,各OBJECT的子命令也可简写,接上OBJECT之后可以在后面再接上具体的OBJECT 支持的选项
help:例如# ip link help可以显示简要的使用信息
1、ip link
# ip link set dev IFACE
网络接口的设置(dev表示设备),IFCAE后可接一些属性,dev可以省略
【root@centos】# ip link set etho down
# ip link show:显示网卡信息
[dev IFACE] :指定接口
eg:ip link show dev ens33
[up] :仅显示处于激活状态的接口
# ip link name NAME :为网络接口重命名
eg:
[root@yph7 ~]# ip link set eno33554984 down --------改名前先禁用网卡 [root@yph7 ~]# ip link set eno33554984 name eno33333333 [root@yph7 ~]# ip link show ------------------网卡重命名成功 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:90:fa:11 brd ff:ff:ff:ff:ff:ff 3: eno33333333: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000 link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff
2、ip addr
STRING:
[label LABEL] : 添加地址时指明网卡别名
[scope {global | link |shost}] :作用域
global :全局可用
link:仅链接可用
host :本机可用
[broadcast ADDRESS] :指明广播地址
[dev DEVICE]
[label PATTERN]
[primary and secondary]
3、#ip route
routing table management
1、添加新路由 : ip route add
# ip route add TARGET via GW dev IFACE src SOURCE_IP
TARGET src
说明:
当为主机路由时:ip
当为网络路由时 :ip/mask,要加子网掩码
src:只有当网卡ip地址被设置多个时才使用这个
eg:
# 指定设备为eth0添加一个路由192.168.1.3,网关为172.16.0.1,这是一个主机路由。网络路由和默认路由参考ifcfg里面的route命令
[root@localhost ~]# ip route addr 192.168.1.3 via 172.16.0.1 dev eth0
2、改变路由 :ip route change
格式:# ip route del TYPE PRIEFIX
eg:
[root@localhost ~]# ip route del 192.168.1.0/24
3、替换或添加一个新路由 :ip route replace
4、删除路由 :ip route delete
格式:# ip route del TARGET
5、查看路由 :ip route show
6、清空路由 :ip route flush
格式:# ip route flush [dev IFACE] [VIA PREFIX]
[dev IFACE] :仅清空和某个接口相关联的路由,若省略,则表示所有的
[via PREFIX] :只清空或者显示与指定网关相关的
eg:
# 删除主机路由
[root@localhost ~]# ip route del 192.168.1.3
# 删除网络路由,要加子网掩码
[root@localhost ~]# ip route del 192.168.1.3/24
# 清空某类路由
[root@yph6 ~]# ip route flush 169/8 ---凡是169网段的都删掉,但不一定能删掉系统创建的路由 [root@yph6 ~]# ip route list 192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.106 metric 1 172.16.0.0/16 dev eth1 proto kernel scope link src 172.16.10.20 169.254.0.0/16 dev eth0 scope link metric 1002 default via 172.16.0.10 dev eth1 src 172.16.10.20 [root@yph6 ~]# ip route flush 169.254/16---在上面的基础上把范围再精确一些,发现就能删掉了 [root@yph6 ~]# ip route list 192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.106 metric 1 172.16.0.0/16 dev eth1 proto kernel scope link src 172.16.10.20 default via 172.16.0.10 dev eth1 src 172.16.10.20
一些eg:
# 显示当前网络地址
[root@localhost ~]# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 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 qlen 1000 link/ether 00:0c:29:d3:73:49 brd ff:ff:ff:ff:ff:ff inet 192.168.22.133/24 brd 192.168.22.255 scope global dynamic ens33 valid_lft 1467sec preferred_lft 1467sec inet6 fe80::e508:e81e:801f:4073/64 scope link valid_lft forever preferred_lft forever 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000 link/ether 52:54:00:84:35:64 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000 link/ether 52:54:00:84:35:64 brd ff:ff:ff:ff:ff:ff [root@localhost ~]#
# 增加一个地址,如果已经有了,则添加的作为备用。ip addr del...用法类似
[root@centos ~]# ip addr add 172....
# 同一块网卡的另一个地址,并给其指明别名label
[root@centos ~]# ip addr add 172.... dev eth0 label "eth0:0"
# 替换,没指明替换哪一个的话,相当于上面的add
[root@localhost ~]# ip addr replace 172....
ss命令
选项:
-t :tcp协议相关
-u :udp协议相关
-w :裸套接字相关
-x :unix sock相关
-l :listen状态的连接
-a :所有
-n :数字格式
-p :相关的程序及PID
-e :扩展的信息
-m:内存用量
-o:计时器信息
FILTER := [ state STATE-FILTER ] [ EXPRESSION ]
常用组合:
-tan,-tanl,-tanlp,-uan
说明:FILTER是过滤器
格式:
[ state STATE-FILTER ] :显示特定状态的连接
[ EXPRESSION ] :自己给定表达式
即( dport = :ssh or sport = :ssh )‘
sport、deport表示仅显示源端口或者目标端口
eg:
# 把源端口和目标端口是22且状态为连接的都显示出来
[root@yph6 ~]# ss -tan state ESTABLISHED `(dport=:22 or sport=:22)` Recv-Q Send-Q Local Address:Port Peer Address:Port 0 52 192.168.0.110:22 192.168.0.104:5115
# 把源端口和目标端口是22的都显示出来
[root@yph6 ~]# ss -tan ‘( dport = :22 or sport = :22 )‘ State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 :::22 :::* LISTEN 0 128 *:22 *:* ESTAB 0 52 192.168.0.110:22 192.168.0.104:5115
LISTEN :监听,等待别人来访问时的服务状态
ESTABLISEHD:已建立的连接,正在通信中
FIN_WAIT_1:断开之类的
FIN_WAIT_2:断开之类的
SYN_SENT:SYN已发送
sYN_RECV:SYN已接送
CLOSED:已关闭
eg:
# 显示所有状态为ESTABLISHED的连接
[root@localhost ~]# ss -tan state ESTABLISHED Recv-Q Send-Q Local Address:Port Peer Address:Port 0 52 192.168.22.133:22 192.168.22.1:50084 0 0 192.168.22.133:22 192.168.22.1:50083 [root@localhost ~]# ^C
# 显示状态为LISTEN的连接,LISTEN可以简写为l
[root@localhost ~]# ss -tanl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 5 192.168.122.1:53 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:*
标签:功能 网络路由 替换 style ble seh source br0 ssi
原文地址:http://www.cnblogs.com/FernLi/p/7028612.html