My machine has two network interfaces, one is wired (eth0) and the other one is wireless (wlan0). The wired one cannot connect to any external NTP server because there is a firewall outside. The wireless one has no such constraint.
Therefore, I want to route all NTP traffic to wlan0. As I know, the NTP traffic go through the UDP 123 port. What I have done is described below.
$ sudo echo "201 ntp.out" >> /etc/iproute2/rt_tables
$ sudo ip route add default via 100.75.0.1 dev wlan0 table ntp.out
$ sudo sysctl -w net.ipv4.tcp_fwmark_accept=1
$ sudo iptables -t mangle -I PREROUTING -p udp --dport 123 -j MARK --set-mark 0xfefa
$ sudo iptables -t mangle -I OUTPUT -p udp --sport 123 -j MARK --set-mark 0xfefa
$ sudo ip rule add fwmark 0xfefa lookup ntp.out
However, it doesn't work. I used Wireshark to track the UDP:123 packets, and found that there is no mark ''fefa'' in the packets.
BTW, I set net.ipv4.tcp_fwmark_accept rather than net.ipv4.udp_fwmark_accept, because there is no net.ipv4.udp_fwmark_accept defined. I also tried to mark TCP packets, but still could not find the mark in those packets.
Could anybody help me solve the problem? I'm using Ubuntu 14.04 LTS.
sudo iptables -t mangle -I PREROUTING -p udp --dport 123 -j MARK --set-mark 0xfefa
, the rest look good.