Connect two networks to share the Internet with GNU / Linux.

I have hired cable Internet, but the cable-modem they have given me is single-user, so to share the Internet by WIFI with the rest of the devices in my house I have to use my old telephone router and a few commands. Can be done.


First, we will activate the ipforwarding editing the sysctl.conf file running, if nano is your favorite editor:

sudo nano /etc/sysctl.conf

and in the following line we change the value 0 to 1:

# net.ipv4.ip_forward = 0 net.ipv4.ip_forward = 1

Next we create a small script to run at system startup with administrator permissions and use iptables to activate the network masking:

sudo nano /etc/init.d/share.sh

We add:

#! / bin / bash iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

In my case the internet enters me through eth0 but you must check the name of your network interface that may change depending on the device or the GNU / Linux distribution used. To do this, you can use ifconfig from a terminal.

Then we execute the following command so that it is executed with the boot of our system in distributions based on Ubuntu / Debian:

sudo update-rc.d share.sh defaults

In those based on Arch Linux we put our script inside /etc/rc.local:

sudo nano /etc/rc.local/share.sh

With this systemd will execute it at system startup.

En OpenSuse instead of creating the script we can use YaST2 to configure our Firewall in graphic mode, which will need to be activated. We mark the option «Network Masking».

And finally we must bear in mind a fundamental concept so that everything works well, Default Gateway.

We must configure our router writing the IP of our wlan0, in my case, in the field corresponding to Default Gateway inside of the router. For this we must log in within the web interface of the same. It is convenient to configure the IP of our PC within the WIFI network manually so that it does not change when the equipment starts.

Thanks to what we have done, we can improve the coverage of our WIFI network at home, since we can place the router anywhere with an electrical outlet, as long as it is within reach of our PC with the two network cards (eth0 and wlan0) .


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

11 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   cvargasc said

    in my case I connect to the internet through a Wisp that gives me access, the equipment I use is a crazy M5 nanostation which I connect through the network cable to my network card of my pc eth0 and at the same time I have I installed a wlan0 wireless network card and I have always wanted to share the internet at home to computers with wifi and I also have a 54mbs tp-link AP and a panel antenna with which I previously connected to the internet.

    For the tutorial you can use the AP instead of the router, the AP in which mode I have to configure.

    regards

    1.    nur said

      Where do you sail from?

  2.   Javier Fernandez said

    That depends on the options that the AP has, I imagine that you can connect to its web interface with a browser and there configure it like any router, the only thing you have to change is the Default Gateway, I hope it has helped you, encouragement.

  3.   Javier Fernandez said

    Yes, it is possible, with that «SWITCH», you have a WAN interface and the other LANs so you can connect it easily, but I wanted to take advantage of my router and not buy anything. So I use the PC as a bridge, the WAN interface would be eth0 and the LAN interface would be WLAN0. The WIFI network is the one that the router has.

  4.   pzero said

    Wouldn't it be possible to put a simple switch at the output and from it (I use dlink units with 1 input 4 outputs) connect the computer as demilitarized and the router to generate a Wifi?
    Now they have given me a router with 4 outputs, but I have its Wi-Fi output canceled and I have the computer as demilitarized, a router that I connect when I need Wi-Fi (phone and tablet), a free cable to update laptops and printer and one for a home PLC network. Before, with a modem, I think I remember that I had used a switch

  5.   Javier Fernandez said

    If you try to share the internet by WIFI directly from the computer with GNU / Linux you will create an Ad-Hoc network with WEP encryption. My Android devices cannot connect to an Ad-Hoc network, plus there is the security issue of WEP networks. Using a WIFI router or wireless access point we have WPA encryption and a network in Infrastructure mode with which we increase security, we can connect with Android and we can increase the range of our WIFI, if we have another computer within the range of the WIFI network we can connect to another wifi router via ethernet (with a cable) and repeat the operation (this time the internet would enter the computer's wifi interface and exit via the ethernet to the new router) so we could connect a third network and share the internet with it in addition to have even more scope. And so on to infinity and beyond.

  6.   Carles said

    I do not know if I have understood it correctly, is this to use the pc as a wifi point in case of having a modem / router without wifi?

  7.   Javier Fernandez said

    I would say that I have recycled my old adsl wifi router, taking advantage of its wifi network by connecting it to the PC with the cable modem via ethernet and to the router via wifi. With this, I reuse what I have saving a little money and, what is more important, I have learned how to do it, it can be used to expand the reach of your Wi-Fi network, or to share the internet.

  8.   MonitoLinux said

    but using firestarter + dhcp3-server it can also be done.
    and the configurations would be done by the firestarter gui

  9.   Javier Fernandez said

    Firestarter is another option but I have not tried it, as you can see with opensuse almost everything is done in graphical mode.

  10.   nelson said

    Using a WIFI router or wireless access point we have WPA encryption and a network in Infrastructure mode with which we increase security, we can connect with Android and we can increase the range of our WIFI, if we have another computer within the range of the WIFI network we can connect to another wifi router via ethernet (with a cable) and repeat the operation (this time the internet would enter the computer's wifi interface and exit via the ethernet to the new router) so we could connect a third network and share the internet with it in addition to have even more scope.

    THERE IT GOES . I have it like that with XP. The internet reaches me through WIFI USB, enters the LAPTOP and leaves through a Router to an AP with DHCP Enabled. All the machines that connect to the AP have internet, I did this with the shared internet connection, but now I want to do it in FEDORA. And it doesn't come out.

    I went to open NETWORK MANAGER and I put fixed ip 192.168.0.1/255 255 255 0 in the LAN and to the WIFI (which has internet) I put SHARE WITH OTHER USERS. But I don't know how to link the router that comes with the internet requests from the machines. Link it to Wifi, I say.

    In the connection sharing of XP is automatic, I appreciate ideas.