关于linux:Linux命令ip

42次阅读

共计 1792 个字符,预计需要花费 5 分钟才能阅读完成。

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

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
  • 增加路由

    # 10.0.0.0/24: 目标网络
    # 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

正文完
 0