ip rule add from 192.168.1.10 table 10 ip rule add from 192.168.2.0/24 table 20
fwmark
将fwmark作为匹配条件时,必须搭配Netfilter一起使用, 这看起来很麻烦, 却是最灵活的匹配条件。如图10-8所示,某公司对外有三条ADSL,我们希望所有HT T P 协议经由第一条ADS L ,SMTP及POP3经由第二条ADSL,其余流量则经由第三条ADSL。可以使用如下的命令组合来达到这样的目的:
1 2 3 4 5 6 7
iptables -t mangle -A FORWARD -i eth3 -p tcp --dport 80 -j MARK --set-mark 1 iptables -t mangle -A FORWARD -i eth3 -p tcp --dport 25 -j MARK --set-mark 2 iptables -t mangle -A FORWARD -i eth3 -p tcp --dport 110 -j MARK --set-mark 2 iptables -t mangle -A FORWARD -i eth3 -j MARK --set-mark 3 ip rule add fwmark 1 table 1 ip rule add fwmark 2 table 2 ip rule add fwmark 3 table 3
[root@localhost ~]# ip rule show 0: from all lookup local 32766: from all lookup main 32767: from all lookup default [root@localhost ~]# [root@localhost ~]# ip rule add from 192.168.1.0/24 table 1 [root@localhost ~]# ip rule add from 192.168.2.0/24 table 2 [root@localhost ~]# [root@localhost ~]# ip rule show 0: from all lookup local 32764: from 192.168.2.0/24 lookup 2 32765: from 192.168.1.0/24 lookup 1 32766: from all lookup main 32767: from all lookup default
ip rule del prio 10 ip rule del from 192.168.1.0/24 ip rule del table 1 ip rule del from 192.168.1.0/24 table 1 prio 10
1 2 3 4 5 6
[root@localhost ~]# ip rule show 0: from all lookup local 10: from 192.168.1.0/24 lookup 1 20: from 192.168.2.0/24 lookup 2 32766: from all lookup main 32767: from all lookup default
在查看路由表之前,首先使用ip rule show命令来查看目前使用了哪些路由表,接着,再使用ip route show [table id | name]命令来查看路由表的内容。例如,可以使用ip route showtable main来查看路由表main的内容,如果省略路由表名称(如ip route show),会默认地查看路由表main的内容。
1 2 3 4 5 6 7 8 9
[root@localhost /]# ip rule show 0: from all lookup local 32766: from all lookup main 32767: from all lookup default [root@localhost /]# [root@localhost /]# ip route show table main 10.10.15.0/25 dev eth0 proto kernel scope link src 10.10.15.46 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.10 default via 10.10.15.1 dev eth0
[root@localhost /]# ip route show table main 10.10.15.0/25 dev eth0 proto kernel scope link src 10.10.15.46 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.10 default via 10.10.15.1 dev eth0
[root@localhost /]# ip route show table main 10.10.15.0/25 dev eth0 proto kernel scope link src 10.10.15.46 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.10 default via 10.10.15.1 dev eth0 [root@localhost /]# [root@localhost /]# ip route add 192.168.2.0/24 via 10.10.15.50 table main [root@localhost /]# [root@localhost /]# ip route show table main 10.10.15.0/25 dev eth0 proto kernel scope link src 10.10.15.46 192.168.2.0/24 via 10.10.15.50 dev eth0 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.10 default via 10.10.15.1 dev eth0
[root@localhost ~]# ip rule show 0: from all lookup local 32766: from all lookup main 32767: from all lookup default [root@localhost ~]# [root@localhost ~]# ip rule add from 192.168.2.0/24 table 10 [root@localhost ~]# [root@localhost ~]# ip route show table 10 [root@localhost ~]# [root@localhost ~]# ip route add 192.168.1.0/24 dev eth1 table 10 [root@localhost ~]# ip route add default via 192.168.1.254 table 10 [root@localhost ~]# [root@localhost ~]# ip route show table 10 192.168.1.0/24 dev eth1 scope link default via 192.168.1.254 dev eth1
3、删除路由
可以使用ip命令来方便地删除路由,我们使用以下示例来说明如何删除路由。首先将路由表10的内容显示出来.,可以看到路由表10中当前有两条路由,接着使用ip route del命令删除默认路由.,在此别忘了指定我们所要删除的是路由表10,否则默认会删除路由表main的默认路由,接着再使用ip route show 命令查看路由表10.,此时路由表10的默认路由已经不存在了,再次使用ip route del命令删除192.168.122.0/24的路由.,最后可以看到路由表10中已经没有任何路由了。
1 2 3 4 5 6 7 8 9 10 11 12
[root@localhost ~]# ip route show table 10 192.168.1.0/24 dev virbr0 scope link default via 192.168.1.254 dev eth1 [root@localhost ~]# [root@localhost ~]# ip route del default table 10 [root@localhost ~]# [root@localhost ~]# ip route show table 10 192.168.1.0/24 dev virbr0 scope link [root@localhost ~]# [root@localhost ~]# ip route del 192.168.1.0/24 table 10 [root@localhost ~]# [root@localhost ~]# ip route show table 10
To free pagecache: # echo 1 > /proc/sys/vm/drop_caches To free dentries and inodes: # echo 2 > /proc/sys/vm/drop_caches To free pagecache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches
MTU丢包
查看:
1.检查接口MTU配置,ifconfig eth1/eth0,默认是1500;
2.进行MTU探测,然后设置接口对应的MTU值;
解决方案:
根据实际情况,设置正确MTU值;
设置合理的tcp mss,启用TCP MTU Probe:
1 2 3 4 5 6
cat /proc/sys/net/ipv4/tcp_mtu_probing: tcp_mtu_probing - INTEGER Controls TCP Packetization-Layer Path MTU Discovery. Takes three values: 0 - Disabled 1 - Disabled by default, enabled when an ICMP black hole detected 2 - Always enabled, use initial MSS of tcp_base_mss.
原理:PAWS(Protect Against Wrapped Sequence numbers),高带宽下,TCP序列号可能在较短的时间内就被重复使用(recycle/wrapped) 就可能导致同一条TCP流在短时间内出现序号一样的两个合法的数据包及其确认包。
查看:
1 2 3 4 5
$netstat -s |grep -e "passive connections rejected because of time stamp" -e "packets rejects in established connections because of timestamp” 387158 passive connections rejected because of time stamp 825313 packets rejects in established connections because of timestamp