0
                       +---+        
            eth1- *.1.6| S |           
              =========|   |           
                       |PC1|private net      --------------------
                       |   |==============|||PC 2 with eth0 *.0.7|||
                       | R |eth0-*.0.6       --------------------
                       +---+

eth1 = interface with internet eth0 = interface private

eth1 and eth0 are two different network

I'd like to share my internet connection to my PC2. I guess it should work with some Iptables rules but doesn't work for me or I don't konw how to do it ...

here is my iptables on PC1:


Chain PREROUTING (policy ACCEPT 6 packets, 789 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain INPUT (policy ACCEPT 6 packets, 789 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 3 packets, 218 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 1 packets, 60 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       2      158 MASQUERADE  all  --  *      eth0    0.0.0.0/0            0.0.0.0/0



Chain INPUT (policy ACCEPT 2796 packets, 273921 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 3217 packets, 335744 bytes)
    pkts      bytes target     prot opt in     out     source               destination

I used this command ( sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE ) on my PC1

I tried lot of tutorial but PC2 can't get access to internet !

What can I do ? I'm completly stuck

4
  • Did you enable forwarding? cat /proc/sys/net/ipv4/ip_forward should give 1. Apr 27, 2015 at 15:17
  • Yes Of course .
    – Dgn_OABS
    Apr 27, 2015 at 15:26
  • Please edit your question adding outputs from sudo iptables -t nat -v -x -n -L and sudo iptables -v -x -n -L. I don't think this target prot opt source destination MASQUERADE all -- anywhere anywhere is correct. Apr 27, 2015 at 15:39
  • I changed my post with your 2 commands !!
    – Dgn_OABS
    Apr 27, 2015 at 16:05

1 Answer 1

0

This:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Should be this:

sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
5
  • Doesn't work for me .. I can't ping internet from my PC 2
    – Dgn_OABS
    Apr 27, 2015 at 16:01
  • Show us. Try to ping internet for awhile from your PC2, and then do again the listings of the current iptables as before and edit them into your question. Apr 27, 2015 at 19:01
  • I can ping eth0 and eth1 but I can't ping the gateway of eth1 from PC2 is it one of my problem?
    – Dgn_OABS
    Apr 28, 2015 at 8:04
  • So I did a traceroute from eth0 to 8.8.8.8 an it works but from PC2 it doesn't work.. I can't understand why ....any help .?
    – Dgn_OABS
    Apr 28, 2015 at 8:42
  • Please do as per my previous comment. I want to observe the packet counters in an attempt to understand where the packets are going. Apr 28, 2015 at 14:32

You must log in to answer this question.

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