Hack Forums
[TUT]Forward internet connection to another machine[TUT] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Linux (https://hackforums.net/forumdisplay.php?fid=85)
+---- Thread: [TUT]Forward internet connection to another machine[TUT] (/showthread.php?tid=3551856)



[TUT]Forward internet connection to another machine[TUT] - Loki123 - Jun 14, 2013

Forward internet connection to another machine.

What the fuck is this ?
If one wants to forward his internet connection to another machine.
Easiest way to explain what this is, is by showing it up like this :
Router* ---> Your computer ---> Second computer.
*Depending on if you use a router or not... heh..

What you need:
  • Linux machine with 2 ethernet network cards
  • second computer

The tutorial is for ethernet cards. I have not tried using wireless, but with some modifications you should be able to manage doing that. Also I will be using IPv4 but not IPv6.

Configure the network cards on your computer
So, lets start of by configuring our network cards.
net0 is the one connected out to the network.
net1 is the one connected to the second machine.

Make sure net0 is configured just as normally but with static IP.
Now, net1 should be something like this :
IP: 192.168.0.1
Netmask : 255.255.255.0

Now take a look at your second computer.
The network should be configured like this :
IP : 192.168.0.2 (Anything from 192.168.0.2-254 just not the same as net1)
Netmask: 255.255.255.0
Default Router : 192.168.0.1
Primary DNS : The DNS server you use. (you should be able to use 8.8.8.8 (Google))

Configuring iptables and your machine
First of all lets make sure your computer allows ip.forwarding...
there are 2 ways to do this :
echo “1″ > /proc/sys/net/ipv4/ip_forward
or
sysctl net.ipv4.ip_forward=1

Now, get to your computer and put these rules in iptables :
iptables -t nat -A POSTROUTING -o net0 -j MASQUERADE
To explain this a little :
-t nat Match NAT packet matching table and specifies the built-in POSTROUTING chain for NAT on the firewall's external networking device (net0).
-A POSTROUTING POSTROUTING allows packets to be altered as they are leaving the firewall's external device.
-o net0 external networking device.
-j MASQUERADE is specified to mask the private IP address of a node with the external IP address of the firewall/gateway.

Then save those rules with :
iptables-save

Now if you run iptables -L the output should be like this :
PHP Code

<?php 
Chain INPUT 
(policy ACCEPT)
target  prot opt source  destination  

Chain FORWARD 
(policy ACCEPT)
target  prot opt source  destination  

Chain OUTPUT 
(policy ACCEPT)
target  prot opt source  destination 

That should do it and you should be able to connect to the internet on both computer.
If you have any trouble, ask away ;*
Have fun ;**


* - Fa-koff - Jun 14, 2013

You can share a wifi connection much easier by setting your wifi adapter to work in "Ad Hoc" mode.
No need for an extra adapter.
The setup is quite simple when you use NetworkManager.


* - Loki123 - Jun 15, 2013

(Jun 14, 2013 08:09 PM)Fa-koff Wrote:  You can share a wifi connection much easier by setting your wifi adapter to work in "Ad Hoc" mode.
No need for an extra adapter.
The setup is quite simple when you use NetworkManager.

Yeah, but I hate Wi-Fi... 🤫


* - katetem - Jun 16, 2013

Already used this method when i'm testing openvz containers...


* - Fa-koff - Jun 16, 2013

(Jun 15, 2013 09:25 AM)Loki123 Wrote:  Yeah, but I hate Wi-Fi... 🤫

Yeah, and I hate being tied down.

Pick and choose.


* - Loki123 - Jun 16, 2013

(Jun 16, 2013 06:17 AM)Fa-koff Wrote:  Yeah, and I hate being tied down.

Pick and choose.

... Wi-Fi on the PS3 sucks and I stream alot of content to it, I guess I will tie my self down. 😎


* - The.Bronze.Shroud - Jun 16, 2013

Thanks Loki, At one time i had to use an old ADSL Modem because a storm killed my main PC and Router. I did this but had to set up a Windows machine (Router would not work on a Linux Platform) and i forwarded the connection to my second computer. Now i have two routers in my house and although it works i still would rather use ethernet than wifi.