linux网络管理及属性命令
admin
2023-07-18 01:22:22
0次

一.Linux网络管理命令

1.Ifconfig命令   

 ifconfig显示当前网络信息

 格式: ifconfig  [INTERFACE]

  常用选项:

      -a:查看所有信息

      ifconfig IFACE up|down  启用|禁用某网卡接口

ifconfig interface [aftype] options | address ...

       # ifconfig IFACE IP/mask [up]

       # ifconfig IFACE IP netmask MASK

启用混杂模式:[-]promisc

Note:启用后立即生效。再次开机后不会再生效!

Eg:禁用eth2接口

[root@localhost ~]# ifconfig eth2 down
[root@localhost ~]# ifconfig      //可以看到eth2已经不再显示了
eth0      Link encap:Ethernet  HWaddr 00:0C:29:7B:65:71  
          inet addr:172.16.249.202  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fe7b:6571/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:159414 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4673 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12952278 (12.3 MiB)  TX bytes:666573 (650.9 KiB)
 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)


2.Route命令

     常用选项: 

     -n: 查看路由表信息

     格式: route  add|del  [-net|-host] target [netmask Nm] [gw Gw]  [[dev] If]

     add | del

        -net: 添加|删除一个网络路由(即添加网段)

        -host: 添加|删除一个主机路由

        -gw : 添加| 删除网关 

        -netmask:添加|删除子网掩码

        default:添加|删除 默认路由

Eg1:给eth0添加一个主机路由为192.168.1.3,默认网关为172.16.0.1

[root@localhost ~]# route add -host 192.168.1.3 gw 172.16.0.1 dev eth0
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.3     172.16.0.1      255.255.255.255 UGH   0      0        0 eth0
192.168.27.0    0.0.0.0         255.255.255.0   U     0      0        0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth2
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         172.16.0.1      0.0.0.0         UG    0      0        0 eth0
删除192.168.1.3这个路由
[root@localhost ~]# route del -host 192.168.1.3 
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.27.0    0.0.0.0         255.255.255.0   U     0      0        0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth2
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         172.16.0.1      0.0.0.0         UG    0      0        0 eth0
[root@localhost ~]# 
删除此路由条目
[root@localhost ~]# route del -net  192.168.0.0/24
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.27.0    0.0.0.0         255.255.255.0   U     0      0        0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth2
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         172.16.0.1      0.0.0.0         UG    0      0        0 eth0
或者[root@localhost ~]# route del -net  192.168.0.0 netmask 255.255.255.0 
Eg2:给eth0接口添加一个网络路由为192.168.0.0默认网关为 172.16.0.1
[root@localhost ~]# route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0
[root@localhost ~]# route add -net 192.168.0.0/24  gw 172.16.0.1 dev eth0


3.Netstat命令

  1>.显示网络连接:

格式: 
netstat  [--tcp|-t] [--udp|-u]  [--raw|-w]  [--listening|-l]  [--all|-a] [--numeric|-n] [--numeric-hosts][--numeric-ports][--numeric-ports] [--symbolic|-N] [--extend|-e[--extend|-e]]


常用选项:

  -t :tcp协议相关

  -u :udp协议相关

  -l :监听的套接字     //常跟-t,-u选项

  -p :打印信息

  -e :扩展信息

  -n :以数字形式显示

  -p: 显示相关pid信息

Eg:以数字形式显示当前主机下tcp协议都监听那些端口并打印出来
[root@chang ~]# netstat -tnlp
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:22                  0.0.0.0:*                   LISTEN      1821/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1612/cupsd          
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      2181/sshd           
tcp        0      0 0.0.0.0:50982               0.0.0.0:*                   LISTEN      1580/rpc.statd      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1478/rpcbind        
tcp        0      0 :::22                       :::*                        LISTEN      1821/sshd           
tcp        0      0 ::1:631                     :::*                        LISTEN      1612/cupsd          
tcp        0      0 ::1:25                      :::*                        LISTEN      1935/master         
tcp        0      0 :::35321                    :::*                        LISTEN      1580/rpc.statd      
tcp        0      0 ::1:6010                    :::*                        LISTEN      2181/sshd           
tcp        0      0 :::111                      :::*                        LISTEN      1478/rpcbind


 

2>.显示路由信息

格式:netstat {--route|-r} [--numeric|-n][--numeric-hosts][--numeric-ports][--numeric-ports] 

常用选项:

 -r: 显示内核路由表

 -n: 以数字格式显示

 

   3>.显示接口统计数据

     netstat  {--interfaces|-I|-i} [iface] [-all|-a] [--extend|-e] [--program|-p]

     常用选项:

      -i : 显示所有的接口信息

      -I IFACE : 显示多指定的接口信息

二.Linux网络属性命令

1.Ip 命令

格式: ip [ OPTIONS ] OBJECT { COMMAND | help }

 OBJECT := { link | addr | route }

   ip link   - network device configuration

          set DEVICE { up | down } 激活| 禁用某接口

          show DEVICE   

          show  up : 仅显示处于激活状态的接口

    ip  address -  protocol address management

       ip addr { add | del } IFADDR dev STRING  

           [label LABEL]:添加地址时指明网卡别名

   [scope {global|link|host}]:指明作用域

 global: 全局可用;

     link: 仅链接可用;

     host: 本机可用; 

         ip address show - look at protocol addresses

[dev DEVICE]

[label PATTERN]

[primary and secondary]

 

 ip address flush - flush protocol addresses

使用格式同show

     ip route - routing table management

 

 ip route add

  添加路由:ip route add TARGET via GW dev IFACE src SOURCE_IP

TARGET:

 主机路由:IP

 网络路由:NETWORK/MASK

 添加网关:ip route add defalt via GW dev IFACE

 ip route delete

 删除路由:ip route del TARGET 

         ip route show

         ip route flush

         [dev IFACE]

         [via PREFIX]

2.ss命令

   格式: ss [options] [ FILTER ]

   常用选项:

      -t : tcp协议相关

      -u : udp协议相关

      -w : 显示裸套接字

      -x  : unix sock 相关

      -l   : 监听状态的连接

      -a  : all

      -n  : 以数字格式显示

      -p : 相关程序及其pid

      -e : extend 的信息

      -m : 内存用量

      -o  : 计时器信息

FILTER := [ state TCP-STATE ] [ EXPRESSION ]

EXPRESSION:

    dport = 

    sport = 

补充: tcp的常见状态

   LISTEN  : 监听

   EATABLISHED :已建立的连接

   FIN_WAIT_1

   FIN_WAIT_2

   SYN_SENT

   SYN_RECV

   CLOSE

ss命令跟netstat命令功能相似,但是要当前连接数较大时用ss命令用着更好。


相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...