0

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.

2
  • Remove sudo iptables -t mangle -I PREROUTING -p udp --dport 123 -j MARK --set-mark 0xfefa, the rest look good.
    – 2707974
    Sep 3, 2015 at 6:54
  • I removed it, but it still does not work.
    – hebothu
    Sep 3, 2015 at 16:35

1 Answer 1

0

I think I find error. In not source port 123 then destination

Change

 sudo iptables -t mangle -I OUTPUT -p udp --sport 123 -j MARK --set-mark 0xfefa

to

 sudo iptables -t mangle -I OUTPUT -p udp --dport 123 -j MARK --set-mark 0xfefa

Also copy all entries except default gateway entry from main table

 sudo ip route show table main | grep -Ev ^default | while read ROUTE ; do ip route add table ntp.out $ROUTE; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .