作用:用于管理网络设备。

ip 命令有多个子命令,且子命令可以简写。

1. ip address

可以简写为 ip a

  • 查看 IP 地址

    [root@localhost ~]# ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
      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
    ...
  • 添加 IP 地址

    [root@localhost ~]# ip address add dev tap1 10.0.0.1/24
  • 删除 IP 地址

    [root@localhost ~]# ip address delete dev tap1 10.0.0.1/24
  • 清空 IP 地址

    [root@localhost ~]# ip address flush dev tap1

2. ip link

可以简写为 ip l

  • 查看设备

    [root@localhost ~]# ip l
    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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
      link/ether 52:54:00:a4:18:9b brd ff:ff:ff:ff:ff:ff
    ...
  • 启停设备

    [root@localhost ~]# ip link set dev tap1 up
    [root@localhost ~]# ip link set dev tap1 down
  • 网桥操作

    # 创建网桥
    [root@localhost ~]# ip link add name br0 type bridge
    
    # 挂载接口
    [root@localhost ~]# ip link set dev tap1 master br0
    
    # 移除接口
    [root@localhost ~]# ip link set dev tap1 nomaster
  • 创建 VXLAN 隧道

    [root@localhost ~]# ip link add name tun0 type vxlan id 42 dstport 4789 remote 192.168.1.20 local 192.168.1.10
  • 删除设备

    [root@localhost ~]# ip link delete dev br0

3. ip route

可以简写为 ip r

  • 查看路由表

    [root@localhost ~]# ip r
    default via 192.168.122.1 dev eth0
    192.168.122.0/24 dev eth0  proto kernel  scope link  src 192.168.122.106
  • 添加路由

    # to 10.0.0.0/24: 目的网络
    # via 10.0.0.1: 下一跳路由器的 IP
    # dev tap1: 数据包出接口
    [root@localhost ~]# ip route add to 10.0.0.0/24 via 10.0.0.1 dev tap1
    
    # 默认路由
    [root@localhost ~]# ip route add default via 192.168.1.1 dev eth0
  • 删除路由

    [root@localhost ~]# ip route delete to 10.0.0.0/24

4. ip neigh

可简写为 ip n

  • 查看 ARP 映射表

    # lladdr: 链路层地址
    [root@localhost ~]# ip n
    192.168.122.1 dev eth0 lladdr 52:54:00:95:7c:07 STALE
    10.0.0.2 dev tap1  FAILED
  • 添加 ARP 映射

    # dev eth0: 通过 eth0 网卡可达 202.38.247.220
    [root@localhost ~]# ip neigh add 202.38.247.220 lladdr 18:66:da:eb:df:92 dev eth0
  • 删除 ARP 映射

    [root@localhost ~]# ip neigh delete 202.38.247.220 dev eth0

gzming
7 声望0 粉丝