Linux 网络命令:ip

  1. ip命令2种使用方式,执行一条命令和批处理模式(执行脚本文件)
ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename

查看帮助:

man ip
ip help
ip address help
  1. 命令模式:
ip [ OPTIONS ] OBJECT { COMMAND | help }

OBJECT := { link | address | addrlabel | route | rule | neigh | ntable | tunnel | tuntap | maddress | mroute |
        mrule | monitor | xfrm | netns |  | tcp_metrics | token | macsec | vrf | mptcp | ioam }

OPTIONS := { -V[ersion] | -h[uman-readable] | -s[tatistics] | -d[etails] | -r[esolve] | -iec | -f[amily] { inet |
        inet6 | link } | -4 | -6 | -B | -0 | -l[oops] { maximum-addr-flush-attempts } | -o[neline] | -rc[vbuf]
        [size] | -t[imestamp] | -ts[hort] | -n[etns] name | -N[umeric] | -a[ll] | -c[olor] | -br[ief] | -j[son] |
        -p[retty] }

常用object:

  • link,网卡设备相关
  • address,IP地址相关
  • route,路由表相关

COMMAND:

  • 支持add、delete、show(list)
  • 有的object不支持全部命令
  • 如果不提供命令,则使用默认命令list或者help

示例:

ip a/addr/address 查看ip地址

ip neigh 查看neighbour表

ip link set link-name up
ip link set link-name down

开关网卡

# 关闭网卡,set down
$ ip link show eno1
2: eno1: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether d8:aa:c1:be:f7:b3 brd ff:ff:ff:ff:ff:ff
$ ip addr show eno1
2: eno1: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether d8:aa:c1:be:f7:b3 brd ff:ff:ff:ff:ff:ff
    altname enp0s31

# 打开网卡,set up
$ ip link show eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether d8:aa:c1:be:f7:b3 brd ff:ff:ff:ff:ff:ff
$ ip addr show eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether d8:aa:c1:be:f7:b3 brd ff:ff:ff:ff:ff:ff
    altname enp0s31
    inet 10.10.9.158/23 brd 10.10.9.255 scope global dynamic noprefixroute eno1
       valid_lft 86374sec preferred_lft 86374sec
    inet6 fe80::ea31:2779:19ff:5555/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

ip route 查看路由表

$ ip route
0.0.0.0/1 via 192.18.0.1 dev tun0 
default via 10.24.9.254 dev eno1 proto dhcp metric 101 
1.1.8.0/24 via 10.24.9.254 dev eno1 
1.2.4.0/24 via 10.24.9.254 dev eno1 
1.8.1.0/24 via 10.24.9.254 dev eno1 
1.8.8.0/24 via 10.24.9.254 dev eno1 
1.1.0.0/14 via 10.24.9.254 dev eno1 
1.2.0.0/13 via 10.24.9.254 dev eno1 
1.4.0.0/16 via 10.24.9.254 dev eno1 

创建vlan

$ sudo ip link add link eno1 name eno1.30 type vlan id 30
$ sudo ip set link eno1.30 up
$ sudo ip addr add 192.168.30.1/24 dev eno1.30

你可能感兴趣的:(网络,linux,tcp/ip)