LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Closed Thread
  Search this Thread
Old 06-24-2006, 05:14 PM   #1
tsunamikitsune
Member
 
Registered: Jun 2006
Location: Dubuque, Iowa
Distribution: Ubuntu
Posts: 51

Rep: Reputation: 15
Internet connection sharing between two Ubuntu computers


I'm still fairly new to Linux, so I don't quite know how to share an internet connection. Here's what my set up looks like:

Cable Modem -> ethernet cable -> Computer 1 (Network Card 1)
Computer 1 (Network Card 2) -> crossover ethernet cable -> Computer 2

In Windows XP, I could connect the crossover cable to another computer running XP and it usually had working internet. Both computers are running Ubuntu, so it shouldn't be too hard to share a connection, right? Like I said, I don't know too much about Linux, so please give me some easy to understand instructions.
 
Old 06-25-2006, 06:28 AM   #2
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
Primarily you need ip-masquerading and then you need to forward requests from comp 1 to 2. This is covered in this article.
The network part of this is that the gateway for comp 2 will be the ip address of network card 2 in comp 1 if you are using static addressing. The network settings are in /etc/network/interfaces.
 
Old 06-25-2006, 04:49 PM   #3
tsunamikitsune
Member
 
Registered: Jun 2006
Location: Dubuque, Iowa
Distribution: Ubuntu
Posts: 51

Original Poster
Rep: Reputation: 15
I have a dynamic ip address, and on Windows I used no-ip to fix that problem. I installed the no-ip package, but I don't know how to set it up or run it. Any experience with this?
 
Old 06-26-2006, 12:04 PM   #4
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
Quote:
Originally Posted by tsunamikitsune
I have a dynamic ip address, and on Windows I used no-ip to fix that problem. I installed the no-ip package, but I don't know how to set it up or run it. Any experience with this?
Reduce the complications by using static addressing.
The dynamic address on the wan (internet) has no bearing on the lan as they are separate networks. The cable modem will pick-up the lease on the wan and then handle the routing to the lan. The key here is not to get confused with addresses and boxes. The ethernet connection to the modem can use dynamic addressing to pick-up an address from the modem. The lan needs to be on a different subnet. eg. if the modem is issuing leases in the 192.168.1.X range then use addresses in the 192.168.0.X range for the lan.
 
Old 05-04-2021, 08:16 AM   #5
Andrew Przelucki
LQ Newbie
 
Registered: May 2021
Distribution: Fedora
Posts: 7

Rep: Reputation: Disabled
There is a simple guide by Oracle at oracle-base.com/articles/linux/use-iptables-to-implement-packet-filtering-and-configure-nat. But I found out, that in Windows, the DNS address that the Linux PC is using, must also be given in Windows.

I have a 3G USB modem connected to my Linux box, and from that I have two Windows PC's that get internet. It's called (kernel) packet forwarding, and it's quite simple and quick to do - when you understand it finally.


1) First you need to enable packet forwarding on your Linux box (see that Oracle guide I provided).

2) Next, you can run these commands, as the Oracle guide says (but wait, and read on):

sudo iptables -I FORWARD -i my_lan_interface -o my_modem_interface -j ACCEPT
sudo iptables -I FORWARD -i my_modem_interface -o my_lan_interface -j ACCEPT
sudo iptables -t nat -I POSTROUTING -o my_modem_interface -j MASQUERADE

When you reboot your linux box, you will have to reenter these commands - I just created a script that runs them at each boot. You can make these changes permanent with the appropriate "service" call (again, see the Oracle guide). But there is a more robust way, that I found on the net:

sudo iptables -t nat -A POSTROUTING -o my_modem_interface -j MASQUERADE --random
sudo iptables -A FORWARD -i my_lan_interface -o my_modem_interface -j ACCEPT
sudo iptables -A FORWARD -i my_modem_interface -o my_lan_interface -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -j DROP

Again, these have to be done at each boot, unless you want to make them permanent. But I recommend running at each boot, as you might want to experiment and change things, and undoing what you saved is another challenge.

You can find your network interfaces by running the command "ifconfig" on Linux (in the terminal), and "ipconfig" on Windows (in the command prompt). The interface names, on Linux, are at the leftmost side, like: enp2s0, enp3s0, enp0s18f2u6, lo, ....


3) You will also have to create a network connection between your Linux box and your Windows box(es). For example:

- On the Linux box connected to the internet (I use Fedora), with the connections manager, I create an Ethernet connection, select the appropriate interface (network card name, enp3s0 in my case) to be used for that connection, and in IPv4 settings set that IPv4 must be used for the connection (IPv6) can be ignored), and select manual address setup. Now add the address 192.168.2.100 - this will be the address of your linux box. The net mask will be set automatically (255.255.255.0, because this is a C class (private) address). Apply your settings and connect.

- On the second PC (connected by Ethernet to the first one above), also create a network connection, select the appropriate network interface (the device/card which is connecting to the first PC), use manual IPv4 setup, set address 192.168.2.101 - this will be the address of this second PC. (On a Windows box, go to "Network and Sharing Center"->"change adapter settings", and pick your network interface that corresponds to your LAN card connected to the first box that already is connected to the internet. Select that interface, right click for Properties, unselect Internet Protocol Version 6, and double click "Internet Protocol Version 4". Now you enter the address 192.168.2.101 - this will be the address of your Windows PC on that interface (on that [LAN/Ethernet] connection)). Tab down so netmask is filled out automatically (255.255.255.0). Now, you must enter the DNS address that your first Linux box is using. My modem uses DNS address 192.168.1.1 (which I can find with the command "nmcli device show <interfacename> | grep IP4.DNS", where interfacename is the name of your Linux interface connected to the internet). (If you connect to the internet with Windows, run "ipconfig" in the terminal/command prompt, look for such info). And that's it. The DNS info is critical to getting an internet connection.


So putting it short:

My modem address: 192.168.1.100, DNS 192.168.1.1.
Linux box address on LAN: 192.168.2.100, packet forwarding enabled with iptables redirecting traffic, as explained above.
Windows box 1 address: 192.168.2.101 with DNS set to 192.168.1.1.
Windows box 2 address: 192.168.2.102 with DNS set to 192.168.1.1.
(All computers connected together by a simple Ethernet switch.)

There is also a guide at: medium.com/@TarunChinmai/sharing-internet-connection-from-a-linux-machine-over-ethernet-a5cbbd775a4f, which tells you to use Google's DNS addresses, instead of the USB modem address I gave above.
 
Old 05-04-2021, 08:44 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Again; check the dates...this one had been closed for *FIFTEEN YEARS*.
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet connection sharing between Ubuntu and Windows 98SE tsunamikitsune Linux - Networking 2 06-23-2006 10:50 AM
internet connection sharing between two computers using crossover cable farnell_mark Debian 1 06-04-2005 04:44 PM
Sharing my Internet Connection from Ubuntu to Windows (XP & 98SE) eminence Linux - Networking 4 05-19-2005 06:05 PM
2x Computers with Slackware 9.1 NFS/Internet PPPD sharing jimdaworm Linux - Networking 2 11-22-2003 10:32 AM
internet connection sharing with two red hat computers. brucedjones Linux - Networking 32 08-18-2003 03:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration