4

I am trying to forward UDP traffic to/from a specific IP to a pseudo-interface:

iptables -I FORWARD -s [WAN-IP] -p udp -j ifb0

I have also tried (without success):

iptables -A OUTPUT -d [WAN-IP] -p udp -j ifb0

I am trying to redirect and apply latency to the traffic, what I have:

ip link set dev ifb0 up
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -p udp -i eth0 -o ifb0 -j ACCEPT
iptables -A FORWARD -p udp -i eth0 -o ifb0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o ifb0 -j MASQUERADE
tc qdisc add dev ifb0 root netem delay 100ms

Network information:

ip route
default via 195.***.***.*** dev pppoe-wan  proto static
192.168.1.0/24 dev br-lan  proto kernel  scope link  src 192.168.1.1
[195.***.***.***] dev pppoe-wan  proto kernel  scope link  src **.***.***.***

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         195.***.***.*** 0.0.0.0         UG    0      0        0 pppoe-wan
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
195.***.***.*** 0.0.0.0         255.255.255.255 UH    0      0        0 pppoe-wan

ifconfig
br-lan    Link encap:Ethernet  HWaddr 30:B5:C2:D7:**:**
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fda5:a926:****::1/60 Scope:Global
          inet6 addr: fe80::32b5:c2ff:fed7:****/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3924668 errors:0 dropped:5 overruns:0 frame:0
          TX packets:6856064 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:285489896 (272.2 MiB)  TX bytes:9801376990 (9.1 GiB)

eth0      Link encap:Ethernet  HWaddr 30:B5:C2:D7:**:**
          inet6 addr: fe80::32b5:c2ff:fed7:****/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6817769 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3926298 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1243564002 (1.1 GiB)  TX bytes:353441588 (337.0 MiB)
          Interrupt:4

eth1      Link encap:Ethernet  HWaddr 30:B5:C2:D7:**:**
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3922867 errors:0 dropped:68 overruns:0 frame:0
          TX packets:6805869 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:340296313 (324.5 MiB)  TX bytes:1166540824 (1.0 GiB)
          Interrupt:5

ifb0      Link encap:Ethernet  HWaddr 2E:13:67:**:**:**
          inet6 addr: fe80::2c13:67ff:****:9593/64 Scope:Link
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:292 errors:0 dropped:0 overruns:0 frame:0
          TX packets:292 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:21661 (21.1 KiB)  TX bytes:21661 (21.1 KiB)

pppoe-wan Link encap:Point-to-Point Protocol
          inet addr:**.***.***.***  P-t-P:195.***.***.***  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1
          RX packets:6801543 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3909873 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:9682888295 (9.0 GiB)  TX bytes:266900462 (254.5 MiB)

Nothing happens.

2 Answers 2

3

This question has been answered on ServerFault:

Adapting the solution given there to your situation yields the following (NOTE: here we're forwarding from the eth0 interface to the ifb0 interface).

Enable forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

Allow traffic through the firewall (if there is one):

iptables -A FORWARD -p udp -i eth0 -o ifb0 -j ACCEPT

Allow traffic for already established connections:

iptables -A FORWARD -p udp -i eth0 -o ifb0 -m state --state ESTABLISHED,RELATED -j ACCEPT

Change the source address on packets going out to the internet:

iptables -t nat -A POSTROUTING -o ifb0 -j MASQUERADE
7
  • I have updated my question, this still does not appear to pass the traffic through ifb0.
    – Tod
    Commented Dec 8, 2017 at 22:18
  • @Tod Could you update your question to include your network interfaces (e.g. ip addr or ifconfig) and routing table (e.g. ip route or route -n)?
    – igal
    Commented Dec 9, 2017 at 0:30
  • @Tod Also, what are you doing to test the configuration?
    – igal
    Commented Dec 9, 2017 at 0:31
  • I have added the information requested and I am using a simple game server which sends UDP I can see the latency in game visually when delaying all traffic just not UDP alone. I am not using ICMP to check ping, etc.
    – Tod
    Commented Dec 9, 2017 at 1:11
  • @Tod Are you trying to route all traffic to the same interface? Also, is it possible that the traffic isn't being routed at all? Local traffic (that doesn't leave the network segment) won't hit the routing table, so the forwarding rules won't get applied.
    – igal
    Commented Dec 9, 2017 at 1:18
0

Make sure forwarding is enabled at kernel. You can enable forwarding as follows

sudo echo 1 > /proc/sys/net/ipv4/ip_forwar

Then try the following as root user

iptables -I FORWARD -s [WAN-IP] -p udp -i source_interface -o ifb0 -j ACCEPT
iptables -A FORWARD -d [WAN-IP] -i ifb0 -o source_interface -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o ifb0 -j MASQUERADE

Explanation: First forward traffic from source interface to ifb0. Forward back the returning traffic to source interface. Rewrite source IP address of outgoing packets with POSTROUTING rules.

Consult this post also https://serverfault.com/questions/431593/iptables-forwarding-between-two-interface

You must log in to answer this question.

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