0

I would like to forward packets between interfaces without using iptables. I am not against iptables per se, I just believe that for my simple needs it's not necessary. However I am unable to do so. Can I?

Here's the scenario: I have a wireless interface and a hardwired interface on host A. My wireless gateway has IP 10.0.0.1. My wireless interface is 10.0.0.12.

So I figure that if I enable port forwarding using sysctl, and create an IP on the network for my wired interface, then create a routing table entry for the host attached to the wired interface (call it host B), then all should be good, no?

So I have:

  • Wireless:
    • Gateway == 10.0.0.1
    • Host A interface == 10.0.0.12
    • Host A netmask == 255.255.255.0
  • Wired:
    • Host A interface == 10.0.0.99
    • Host B interface == 10.0.0.100, plugged into Host A.
    • routing table entry for Host B with a netmask of 255.255.255.255.

I can ping and ssh into Host B from Host A. But when I try to ping the gateway from host B, I see a lot of these on Host A's wired interface:

12:56:55.211866 ARP, Request who-has gateway tell 10.0.0.100, length 46
12:56:56.211751 ARP, Request who-has gateway tell 10.0.0.100, length 46
12:56:57.214187 ARP, Request who-has gateway tell 10.0.0.100, length 46
12:56:58.211834 ARP, Request who-has gateway tell 10.0.0.100, length 46
...

Is there something I'm missing, or do I need iptables?

Here is my routing table on Host A:

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.0.0.1        0.0.0.0         UG        0 0          0 wlp3s0
10.0.0.0        0.0.0.0         255.255.255.0   U         0 0          0 wlp3s0
10.0.0.100      0.0.0.0         255.255.255.255 UH        0 0          0 enp0s25

adTHANKSvance!

BTW, on Host A:

# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
  • Change the address of the network between A and B to anything but 10.0.0.0, such as 10.0.1.0/24, 192.168.0.0/24 etc. Even better, use a /30 mask as you only need two IP addresses. – garethTheRed Nov 13 '15 at 20:35
  • If I did that, though, gareth then my B cannot reach the internet. Packets coming back to my router won't know how to get to host B. – Mike S Nov 13 '15 at 22:34
  • You would need to add a static route in your router to direct all traffic to B through A. Whether you can configure static routes on your router depends on the model unfortunately. If it doesn't, you could always see if you can install DD-WRT or Open-WRT on it. – garethTheRed Nov 14 '15 at 10:30
2

You cannot have 2 different netblocks with the same address space. Hence, it is not of use doing ip_forward as ip_forward=1 is for routing. So either you use different networks in both netblocks, or if you really want this setup, setup a bridge.

If in Debian

$sudo apt-get install bridge-utils

vi /etc/network/interfaces

   allow-hotplug wlan0  
      iface wlan0 inet manual

   auto eth0   
      iface eth0 inet manual

   auto br0  
   iface br0 inet static  
   bridge_ports eth0 wlan0  
      address 10.0.0.1  
      netmask 255.255.255.0

$sudo service networking restart
  • Thanks for the information about bridging. I have Fedora. I tried to set up a bridge but still no joy. Furthermone, for whatever reason setting up my two files- ifcfg-enp0s25 and ifcfg-br0- AND telling Network Manager to keep its big fat nose out of there, managed to break authentication on my Wireless. sigh So I removed those files, put back the old config file, and rebooted. The system and wireless are back. Guess I'll use iptables like a good boy. – Mike S Nov 13 '15 at 20:49
  • I really wanted to use my little Raspberry Pi on the road, then plug it into my home network and not have to change its IP address... just tell the laptop to stop bridging with some scripts or what have you, but I think I'm better off just buying another Pi. They're cheap. – Mike S Nov 13 '15 at 20:51
  • I am using a mostly rapsberry look-alike, a lamobo r1, in bridge mode and doing nat to the outside. Have you changed in hostpad.conf the interface directive from the wifi to the new bridge interface? However, do please note I have one interface out of the bridge to get IP through DHCP to foreign networks that routes to 5 others that are bridged. – Rui F Ribeiro Nov 13 '15 at 21:02
  • I realized that I must NAT my raspberry pi. I need it to get to the Internet and my HostA's IP address will be changing depending on if I'm home or on the road. So a simple bridge will not do it. Thanks for the suggestions. Disappointed that I couldn't get bridging to work. But it doesn't matter anyway, I've concluded. – Mike S Nov 13 '15 at 22:50
  • Have a look at the lamobo R1 wiki.lamobo.org/index.php/Lamobo_R1 or the turris omnia router ; consider having a wifi + 2 ethernets, it is totally worth it. ethernet+wifi bridged routing to another ethernet. A last question, why you do not disable network manager? – Rui F Ribeiro Nov 13 '15 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.