Skip to contentSkip to conversation

Forward traffic between two interfaces on the same host

DISCUSSION Kostas Pelechrinis 3 participants 4 messages Oct 7, 2009 – Oct 8, 2009

lore
Share & tools
lore
#0 lore raw

Hi all,

I am new in using iptables so I would like to do a few questions for something that maybe many of you find easy :)

In particular, I have a laptop with two wireless interfaces, a Wifi and a 3G. I would like to share the 3G broadband connection available on this laptop with other machines within my home/internal network through the wifi interface. I would like to ask if such functionality is possible to be implemented using iptables.

Even more specific what I need is a 'relay'-like functionality. Let's assume that laptop A has the two interfaces and laptop B has only a wifi interface. Laptop-B will be connected with laptop A through the wifi and laptop A needs to serve all the internet requests of laptop B through the 3G usb modem interface.

I think that I need to use rules like the following for laptop A :

(I use the names wifi0 and 3g0 for the corresponding interfaces and xxx.yyy.zzz.www for the ip of the 3G interface) iptables -A FORWARD -i wifi0 -o 3g0 -j ACCEPT
iptables -A FORWARD -i 3g0 -o wifi0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -s 192.168.0.0/24 -o eth0 -j SNAT --to-source xxx.yyy.zzz.www

Do I miss something here ? Do I need to take care of something else as well?

Thanks a lot for the help

#1 lore raw

2009/10/7 Kostas Pelechrinis <[email protected]>:

Quoted 8 lines

Hi all,

I am new in using iptables so I would like to do a few questions for something that maybe many of you find easy :)

In particular, I have a laptop with two wireless interfaces, a Wifi and a 3G.  I would like to share the 3G broadband connection available on this laptop with other machines within my home/internal network through the wifi interface.  I would like to ask if such functionality is possible to be implemented using iptables.

Even more specific what I need is a 'relay'-like functionality.  Let's assume that laptop A has the two interfaces and laptop B has only a wifi interface.  Laptop-B will be connected with laptop A through the wifi and laptop A needs to serve all the internet requests of laptop B through the 3G usb modem interface.

Quoted 8 lines

I think that I need to use rules like the following for laptop A :

(I use the names wifi0 and 3g0 for the corresponding interfaces and xxx.yyy.zzz.www for the ip of the 3G interface) iptables -A FORWARD -i wifi0 -o 3g0 -j ACCEPT
iptables -A FORWARD -i 3g0 -o wifi0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -s 192.168.0.0/24 -o eth0 -j SNAT --to-source xxx.yyy.zzz.www

Do I miss something here ?  Do I need to take care of something else as well?

Check that forwarding is turned on in the kernel...

sysctl net.ipv4.ip_forward should return net.ipv4.ip_forward=1, if it doesn't execute 'sysctl -w net.ipv4.ip_forward=1' to enable it.

Not sure on the NAT rules as I have very little to do with NAT as we're using iptables on a private internal network where the address space in the private ranges is more than adequate enough (using all 3 classes of private addresses)

Signature · 5 lines
Richard Horton
Users are like a virus: Each causing a thousand tiny crises until the
host finally dies.
http://www.solstans.co.uk - Solstans Japanese Bobtails and Norwegian Forest Cats
http://www.pbase.com/arimus - My online photogallery
#2 lore raw

2009/10/7 Richard Horton <[email protected]>:

Quoted 20 lines

2009/10/7 Kostas Pelechrinis <[email protected]>:

Quoted 8 lines

Hi all,

I am new in using iptables so I would like to do a few questions for something that maybe many of you find easy :)

In particular, I have a laptop with two wireless interfaces, a Wifi and a 3G.  I would like to share the 3G broadband connection available on this laptop with other machines within my home/internal network through the wifi interface.  I would like to ask if such functionality is possible to be implemented using iptables.

Even more specific what I need is a 'relay'-like functionality.  Let's assume that laptop A has the two interfaces and laptop B has only a wifi interface.  Laptop-B will be connected with laptop A through the wifi and laptop A needs to serve all the internet requests of laptop B through the 3G usb modem interface.

Quoted 8 lines

I think that I need to use rules like the following for laptop A :

(I use the names wifi0 and 3g0 for the corresponding interfaces and xxx.yyy.zzz.www for the ip of the 3G interface) iptables -A FORWARD -i wifi0 -o 3g0 -j ACCEPT
iptables -A FORWARD -i 3g0 -o wifi0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -s 192.168.0.0/24 -o eth0 -j SNAT --to-source xxx.yyy.zzz.www

Do I miss something here ?  Do I need to take care of something else as well?

Check that forwarding is turned on in the kernel...

Quoted 9 lines

sysctl net.ipv4.ip_forward should return net.ipv4.ip_forward=1, if it doesn't execute 'sysctl -w net.ipv4.ip_forward=1' to enable it.

Not sure on the NAT rules as I have very little to do with NAT as we're using iptables on a private internal network where the address space in the private ranges is more than adequate enough (using all 3 classes of private addresses)

In addition to Richard's comments: It seems wrong to suddenly have eth0 on the nat-rule instead of 3g0. Also, if you get a dynamic ip-address on the 3g-interface, you might want to use MASQUERADE instead of SNAT.

/Oskar

#3 lore raw

Hi all,

thanks a lot for the hints. Infact there was a typo with eth0 there :). So Oskar you mean that instead of using the 3rd rule to use something like:

iptables -A POSTROUTING -t nat -o 3g0 -j MASQUERADE

in case that the ip of the 3g interface is not static, right?

Thanks a lot again for the tips !

Quoted 74 lines · Oskar Berggren

From: Oskar Berggren <[email protected]>
Subject: Re: Forward traffic between two interfaces on the same host
To: "Kostas Pelechrinis" <[email protected]>, [email protected]
Date: Wednesday, October 7, 2009, 12:24 PM
2009/10/7 Richard Horton <[email protected]>:

Quoted 4 lines

2009/10/7 Kostas Pelechrinis <[email protected]>:

Quoted 3 lines

Hi all,

I am new in using iptables so I would like to do a

few questions for something that maybe many of you find easy :)

Quoted 2 lines
Quoted 2 lines

In particular, I have a laptop with two wireless

interfaces, a Wifi and a 3G.  I would like to share the 3G broadband connection available on this laptop with other machines within my home/internal network through the wifi interface.  I would like to ask if such functionality is possible to be implemented using iptables.

Quoted 2 lines
Quoted 2 lines

Even more specific what I need is a 'relay'-like

functionality.  Let's assume that laptop A has the two interfaces and laptop B has only a wifi interface. Laptop-B will be connected with laptop A through the wifi and laptop A needs to serve all the internet requests of laptop B through the 3G usb modem interface.

Quoted 2 lines
Quoted 2 lines

I think that I need to use rules like the

following for laptop A :

Quoted 2 lines
Quoted 2 lines

(I use the names wifi0 and 3g0 for the

corresponding interfaces and xxx.yyy.zzz.www for the ip of the 3G interface)

Quoted 2 lines
Quoted 2 lines

iptables -A FORWARD -i wifi0 -o 3g0 -j ACCEPT
iptables -A FORWARD -i 3g0 -o wifi0 -m state

--state ESTABLISHED,RELATED -j ACCEPT

Quoted 1 line
Quoted 1 line

iptables -A POSTROUTING -t nat -s 192.168.0.0/24

-o eth0 -j SNAT --to-source xxx.yyy.zzz.www

Quoted 2 lines
Quoted 2 lines

Do I miss something here ?  Do I need to take

care of something else as well?

Quoted 4 lines

Check that forwarding is turned on in the kernel...

sysctl net.ipv4.ip_forward should return

net.ipv4.ip_forward=1, if it

Quoted 1 line

doesn't execute 'sysctl -w net.ipv4.ip_forward=1' to

enable it.

Quoted 2 lines

Not sure on the NAT rules as I have very little to do

with NAT as

Quoted 1 line

we're using iptables on a private internal network

where the address

Quoted 1 line

space in the private ranges is more than adequate

enough (using all 3

Quoted 3 lines

classes of private addresses)

In addition to Richard's comments: It seems wrong to suddenly have
eth0 on the nat-rule instead of 3g0. Also, if you get a dynamic
ip-address on the 3g-interface, you might want to use MASQUERADE
instead of SNAT.

/Oskar
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html