用ip指令確認路由表(route table) 含IPv6操作


顯示主路由
ip route show
ip -6 route show
只要在ip後面加上-6就可確認IPv6的部份

ip route show table local
有時候table表名稱會用號碼, 可以從下面系統設定擋看到
  • Ubuntu使用/etc/iproute2/rt_tables
  • 其他裝置可能使用 /data/misc/net/rt_tables
ip route show table 0
可以看所有的設定

ip指令可縮寫,但是不是所有裝置都支援縮寫,下面舉例
  • ip r l 等同ip route list
  • ip r s 等同ip route show
查詢特定IP最後走的網路裝置
以IP是193.233.7.82為例
ip route get 193.233.7.82
可縮寫成ip r g 193.233.7.82
193.233.7.82 via 10.129.159.254 dev eth0  table eth0  src 10.129.145.46  uid 0 cache

顯示所有網路地址
ip address show
可縮寫成ip a或ip a s
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    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
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 0c:f0:b4:1b:0b:2e brd ff:ff:ff:ff:ff:ff
    inet 10.129.145.46/20 brd 10.129.159.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ef0:b4ff:fe1b:b2e/64 scope link
       valid_lft forever preferred_lft forever
3: teql0: mtu 1500 qdisc noop state DOWN group default qlen 100
    link/void

顯示ip鏈路狀態
ip link list
1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 0c:f0:b4:1b:0b:2e brd ff:ff:ff:ff:ff:ff
3: teql0: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 100
    link/void

顯示鄰居表
ip neigh show
10.129.159.254 dev eth0 lladdr 40:7c:7d:96:cf:ac REACHABLE
10.129.145.44 dev eth0 lladdr 34:97:f6:83:84:ec DELAY
fe80::1e49:7bff:fe85:1305 dev eth0 lladdr 1c:49:7b:85:13:05 router STALE

顯示mac位址
ip maddress
1:  lo
  inet  225.0.71.1
  inet  224.0.0.1
  inet6 ff02::1
  inet6 ff01::1
2:  eth0
  link  33:33:00:00:00:01
  link  01:00:5e:00:00:01
  link  33:33:ff:1b:0b:2e
  link  01:00:5e:00:47:01
  link  01:00:5e:01:04:c0
  inet  224.1.4.192
  inet  225.0.71.1
  inet  224.0.0.1
  inet6 ff02::1:ff1b:b2e
  inet6 ff02::1
  inet6 ff01::1
3:  teql0
  inet6 ff02::1
  inet6 ff01::1

清除所有ipv4路由cache
ip route flush cache

Ubuntu 16.04預設沒使用iptables

列出rule
iptables -S -t mangle
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-N bw_mangle_POSTROUTING
-N idletimer_mangle_POSTROUTING
-N natctrl_mangle_FORWARD
-A INPUT -i eth0 -j MARK --set-xmark 0x30064/0xffffffff
-A FORWARD -j natctrl_mangle_FORWARD
-A POSTROUTING -j bw_mangle_POSTROUTING
-A POSTROUTING -j idletimer_mangle_POSTROUTING
-A bw_mangle_POSTROUTING -m owner --socket-exists
-A natctrl_mangle_FORWARD -p tcp -m tcp --tcp-flags SYN SYN -j TCPMSS --clamp-mss-to-pmtu

清除iptables的所有rule
iptables -F
iptables -X

查DNS IPv4/IPv6
host -t AAAA tock.stdtime.gov.tw
tock.stdtime.gov.tw has no AAAA record

host -t A tock.stdtime.gov.tw
tock.stdtime.gov.tw has address 211.22.103.157

加上-v 可以印出很多東西

常用DNS IPv6
Google DNS: [2001:4860:4860::8888] 和 [2001:4860:4860::8844]
Hinet DNS: [2001:b000:168::1] 和 [2001:b000:168::2]
Cloudflare DNS: [2606:4700:4700::1111] 和 [2606:4700:4700::1001]
IBM DNS: [2620:fe::fe]


查看網域的對應IP
nslookup www.google.com.tw
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
Name: www.google.com.tw
Address: 142.251.42.227
Name: www.google.com.tw
Address: 2404:6800:4012:3::2003

清除DNS
for Ubuntu 22.04

檢查DNS daemon狀態
sudo systemctl is-active systemd-resolved

resolvectl statistics
確認目前DNS暫存目前狀況

resolvectl flush-caches
清除DNS暫存


Ping IPv6主機
ping6 ff02::1
ping6 2001:b000:168::1
ping6 2001:b000:168::2
-c 5 測5次
-s 100 封包大小
-M do route的時候可重打包
-I eth0 指定interface

留言