网络管理常用命令

网络管理常用命令

ifconfig

查看当前处于活动状态的所有网络接口

[root@localhost yum.repos.d]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.72.128  netmask 255.255.255.0  broadcast 192.168.72.255
        inet6 fe80::b08f:bae9:6053:b35b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c5:83:57  txqueuelen 1000  (Ethernet)
        RX packets 21537  bytes 25164903 (23.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10645  bytes 1026509 (1002.4 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

仅查看eth0网卡状态

[root@localhost network-scripts]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.72.128  netmask 255.255.255.0  broadcast 192.168.72.255
        inet6 fe80::b08f:bae9:6053:b35b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c5:83:57  txqueuelen 1000  (Ethernet)
        RX packets 5531  bytes 511537 (499.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7288  bytes 916789 (895.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

查看所有网卡状态信息, 包括禁用和启用

[root@localhost ~]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.72.128  netmask 255.255.255.0  broadcast 192.168.72.255
        inet6 fe80::b08f:bae9:6053:b35b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c5:83:57  txqueuelen 1000  (Ethernet)
        RX packets 6962  bytes 641700 (626.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9261  bytes 1147273 (1.0 MiB)
        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

ip

link网络接口属性
addr协议地址
route路由

查看网络接口所有地址

[root@localhost ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:c5:83:57 brd ff:ff:ff:ff:ff:ff

显示报文统计信息

[root@localhost ~]# ip -s link show 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0       
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:c5:83:57 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast   
    1029496    11223    0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    1836685    15127    0       0       0       0       

启用或禁用网络接口ip link set DEV {up|down}

[root@localhost ~]# ip link set lo down
[root@localhost ~]# ip link set lo up

ip addr add ADDRESS dev DEV:添加IP地址

[root@localhost ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:c5:83:57 brd ff:ff:ff:ff:ff:ff
    inet 192.168.72.128/24 brd 192.168.72.255 scope global noprefixroute dynamic ens33
       valid_lft 1255sec preferred_lft 1255sec
    inet6 fe80::b08f:bae9:6053:b35b/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@localhost ~]# ip addr add 192.168.1.1/24 dev eth0
[root@localhost ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:c5:83:57 brd ff:ff:ff:ff:ff:ff
    inet 192.168.72.128/24 brd 192.168.72.255 scope global noprefixroute dynamic ens33
       valid_lft 1077sec preferred_lft 1077sec
    inet 192.168.1.1/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::b08f:bae9:6053:b35b/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

ip addr del ADDRESS dev DEV:删除IP地址

[root@localhost ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:c5:83:57 brd ff:ff:ff:ff:ff:ff
    inet 192.168.72.128/24 brd 192.168.72.255 scope global noprefixroute dynamic eth0
       valid_lft 1697sec preferred_lft 1697sec
    inet 192.168.1.1/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::b08f:bae9:6053:b35b/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@localhost ~]# ip addr del 192.168.1.1/24 dev eth0
[root@localhost ~]# ip addr show ens33
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:c5:83:57 brd ff:ff:ff:ff:ff:ff
    inet 192.168.72.128/24 brd 192.168.72.255 scope global noprefixroute dynamic eth0
       valid_lft 1658sec preferred_lft 1658sec
    inet6 fe80::b08f:bae9:6053:b35b/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

ip addr show DEV:查看网络接口的地址

[root@localhost ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:c5:83:57 brd ff:ff:ff:ff:ff:ff
    inet 192.168.72.128/24 brd 192.168.72.255 scope global noprefixroute dynamic ens33
       valid_lft 1462sec preferred_lft 1462sec
    inet6 fe80::b08f:bae9:6053:b35b/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

ss

ss是一种网络状态查看工具,取代netstat

-ttcp协议相关
-uudp协议相关
-w裸套接字相关
-xunix套接字相关
-llisten状态的连接
-a所有
-n数字格式
-p相关的程序及pid
-e扩展的信息
-m内存用量
-o显示计时器信息

常用组合:

[root@localhost ~]# ss -antlp
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128            *:22                         *:*                   users:(("sshd",pid=1078,fd=3))
LISTEN      0      100    127.0.0.1:25                         *:*                   users:(("master",pid=1365,fd=13))
LISTEN      0      128           :::22                        :::*                   users:(("sshd",pid=1078,fd=4))
LISTEN      0      100          ::1:25                        :::*                   users:(("master",pid=1365,fd=14))

[root@localhost ~]# ss -tan
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128            *:22                         *:*                  
LISTEN      0      100    127.0.0.1:25                         *:*                  
ESTAB       0      36     192.168.72.128:22                 192.168.72.1:54438              
LISTEN      0      128           :::22                        :::*                  
LISTEN      0      100          ::1:25                        :::*     
[root@localhost ~]# ss -tanl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128            *:22                         *:*                  
LISTEN      0      100    127.0.0.1:25                         *:*                  
LISTEN      0      128           :::22                        :::*                  
LISTEN      0      100          ::1:25                        :::*      
[root@localhost ~]# ss -anu
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
UNCONN      0      0      127.0.0.1:323                        *:*                  
UNCONN      0      0              *:68                         *:*                  
UNCONN      0      0            ::1:323                       :::*       

常见端口:

http80/tcp
https443/tcp
ssh22/tcp
ftp20,21/tcp
mysql3306/tcp
rsync873/rsync
redis6379/tcp
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值