發現rootfs裡面有個檔案 /etc/iptable2/rt_tables
了解一下
更新記錄
item | note |
---|---|
20160804 | 第一版 |
目錄
Routing Tables
- Linux kernel 2.2 and 2.4 support multiple routing tables
- Beyond the two commonly used routing tables
- the local and main routing tables
- the kernel supports up to 252 additional routing tables
- kernel config 可以設定是否開啟支援ip multiple table
目前預設都是打開 CONFIG_IP_MULTIPLE_TABLES - ip table優先順序寫在/etc/iptabe2/rt_tables裡面 (數字越小的最先比較判斷,即0為最高優先table)
- 即使沒有/etc/iptable2/rt_tables檔案,系統裡面還有預設(local及main的table)
IP Routing
1 | $ cat /etc/iproute2/rt_tables |
- <1> The local table is a special routing table maintained by the kernel1>
- <2> The main routing table is the table operated upon by route and, when not otherwise specified, by ip route2>
板端實際狀態
只有eth0介面
- netstat -rn (同route -n)
1 | gk350a :[~]# netstat -rn |
- rule tabe
目前有 local > main > default (3個table)
1 | gk350a :[~]# ip rule show |
default table 內容為空的
1 | gk350a :[~]# ip route show table local |
只有eth0& ppp2 介面
- netstat -rn
1 | gk350a :[~]# netstat -rn |
- rule tabe
1 | gk350a :[~]# ip rule show |
1 | gk350a :[~]# ip route show table local |
ip command
1 | gk350a :[~]# ip |
ip rule show 查看目前有多少table表
- 目前有local > pppoe > main > default (共4個table)
1 | gk350a :[~]# ip rule show |
ip route show xx (查看table內容)
- ip route show (預設是man table)
1 | gk350a :[~]# ip route show |
- ip route show table local
1 | gk350a :[~]# ip route show table local |
Listing the Routing Policy Database (RPDB)
1 | gk350a :[~]# ip rule show |
Other
Promiscuous mode
當你查看ifconfig設定值都正確,但網路封包就是出的去進不來,
此時可以開啟(Promiscuous mode),測試若就進的來,表示你的routing table有問題
- Following will put the interface in promiscuous mode.
1 | ifconfig eth0 promisc |
- Following will put the interface in normal mode.
1 | ifconfig eth0 -promisc |
kernel config
- IP: policy routing
決定是否開啟
1 | [*] TCP/IP networking |
1 | CONFIG_IP_MULTIPLE_TABLES: |
- 參考說明來源: Policy based routing MICRO-HOWTO
1 | 4.1. Listing rules. |
rt_tables實際例子
有空找個實際的硬体來試一下
有兩個網卡,預設gateway為eth0 (19.86.101.x)
1 | # ifconfig -a |
1 | # netstat -rn |
問題:無法由外部ping到19.86.100.176
- When you ping the IP address 19.86.100.176 from outside your network you may notice that it will not be pingable.
In order to implement this, you need a create a new policy in the routing table
create a new policy routing table entry in /etc/iproute2/rt_tables file
1 | echo "1 admin" >> /etc/iproute2/rt_tables |
- add the routing entries in the admin table
1 | ip route add 19.86.100.0/24 dev eth1 src 19.86.100.176 table admin |
- All the rules are executed in the ascending order.
1 | <1> ip rule add from 19.86.100.176/24 table admin |
說明
- <1> all the traffic going to eth1’s IP needs to use the “admin” routing table instead of “main”1>
- <2> all the outgoing traffic from eth1’s IP needs to use the “admin” routing table instead of “main” one.2>
- <3> used to commit all these changes in the previous commands3>
verify that your changes are made appropriately using the following command
# ip rule show
0: from all lookup local
32764: from all to 19.86.100.176/24 lookup admin
32765: from 19.86.100.176/24 lookup admin
32766: from all lookup main
32767: from all lookup default