March 19, 2024, 10:29:54 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Internet Sharing in Linux / NAT How to  (Read 140652 times)

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
Internet Sharing in Linux / NAT How to
« on: January 08, 2004, 05:40:46 PM »
Here we will learn how to configure your linux box to share one internet connection over your lan
First make a file named 'rc.nat' and put the following script in it.
Code: [Select]


  # Defines the location of iptables executables.
iptables=/sbin/iptables
 
  #Clears if any old iptable rules/ policies are there.
iptables --flush -t nat

 # Now we will do Masquerading ie. we are doing NAT.
iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT

 # Enabling packet forwarding.
echo 1 > /proc/sys/net/ipv4/ip_forward


Now save this rc.nat in /etc/rc.d/ and make it executable by
Code: [Select]
chmod 755 /etc/rc.d/rc.nat

Now add the following lines in your /etc/rc.d/rc.local so that every time you start your computer it get executed  automatically.
Code: [Select]
/etc/rc.d/rc.nat

Now in your clients make sure you have set the gatway as the ip of your computer which is connected directly to internet and also that you have entered right nameserver (DNS) in the dns list of clients.
Now you should be able to share internet after executing this script.

NOTE :: When you run this script you should also use a good firewall.

Offline digimart

  • New Member
  • Posts: 3
    • DigiMart
Internet Sharing in Linux / NAT How to
« Reply #1 on: January 08, 2004, 06:38:28 PM »
Thanks for good tip.

Pls advise, that in case we have a internet via satellite setup (One-Way). In it the downlinkis through DVB card, and uplink through dialup modem, and the internet is shared on LAN.

As Linux drivers and front-end for our DVB cards ( Technisat B2C2 chip ), are not available on the net <I hv atleast searched at all places, and not able to find>.

So what I did is that I hv set  2 PCs. PC-1 has dialup modem, and running under linux, whereas PC-2 has DVB card, and running under Winxp.

So will your code work in my case too ?

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
Internet Sharing in Linux / NAT How to
« Reply #2 on: January 09, 2004, 04:30:48 PM »
Well here we are basically doing Network Address Translation.  So if anyone makes request to internet first it get translated as it is from the server itself and when the server receives back the reply it tanslates that it goto its original place from where it was requested.
So you can use that in the modem for uplink but i suggest if you are not able to find the drivers then.. connect your DVB card and modem to winxp computer and then connect your linux box to winxp and then your linux to lan..
Some thing like this..
Code: [Select]
Satellite & Modem --> WinXP box --> Linux Box -->  your LAN In this setup you can still take full advantage of Linux Flexibility and can keep your LAN secure enough. Also I suggest that you can use your any low end (spare) pc to connect directly to internet.

Offline amith

  • Linux Noob !
  • *
  • Posts: 4
Thanks for Linux Tutorials
« Reply #3 on: January 14, 2004, 04:37:50 AM »
I will try now all the squid configuration and i will b back/b> :lol:

Offline ozioma

  • Tux Awared
  • **
  • Posts: 35
I NEED YOUR HELP
« Reply #4 on: May 22, 2004, 12:06:59 PM »
PLEASE HOW DO I SHARE MY INTERNET CONNECTION OVER MY LAN WITH MY LINUX SERVER WHAT IS THE COMMAND TO MAKE THE FILE rc.nat AND THE COMMAND TO SAVE IT IN /etc/rc.d/

ALSO HOW DO I EDIT IT

THANKS

OZIOMA

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
Internet Sharing in Linux / NAT How to
« Reply #5 on: May 22, 2004, 02:56:55 PM »
You are pretty new.. it is very simple.. if u want to do it from command line then can use vi.. ie. to make rc.nat do " vi rc.nat" then it will open a new file.. type stuff i mentioned and then save it using
":save /etc/rc.d/rc.nat"

or u can use graphical editor..

Offline ozioma

  • Tux Awared
  • **
  • Posts: 35
HELP AGAIN
« Reply #6 on: May 22, 2004, 03:25:03 PM »
PLEASE IS THERE ANY WAY I CAN BROWSE THE INTERNET FROM MY WORKSTATION WITHOUT SETTING THE CLIENTS GATEWAY AS THE IP ADDRESS OF THE SERVER LIKE CIM MY FORMER SERVER ALL WE NEEDED DO WAS CONFIGURE THE INTERNET EXPLORER TO USE PORT 8080 AND THEN PUT THE IP OF THE SERVER WITHOUT CONFIGURING THE GATEWAY

THANKS

OZIOMA

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
Internet Sharing in Linux / NAT How to
« Reply #7 on: May 23, 2004, 03:21:07 AM »
If you are looking for that then you need squid proxy. see Squid proxy configuration.
BTW you can also set dhcp server on ur linux box so that you don't have to configure every box. Just set your clients to obtain ip and other information from dhcp server. See DHCP server linux how to

Lastly I suggest you to read some stuff about networking to clear your concepts..

Offline kisakye

  • Linux Noob !
  • *
  • Posts: 4
how to share an internet connection
« Reply #8 on: May 30, 2004, 01:20:26 PM »
hi everyone am still wondering after writing out that script which ricky gave will my box linux be able to work as a server hence work with windows machines on the  network??
thanks

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
Internet Sharing in Linux / NAT How to
« Reply #9 on: May 30, 2004, 01:24:13 PM »
Yes , I can be gateway for any machine on any OS untill that machine uses universal TCP/IP protocol

Offline JOJ

  • New Member
  • Posts: 1
VSAT on Linux
« Reply #10 on: June 25, 2004, 12:55:09 AM »
javascript:emoticon(%27%3Acry%3A%27). Hi everyone there.... I am connecting to Internet through Very Small Sperture Terminal (VSAT), and according to our ISP it will only work in Windows Servers. I have a lot of problems dealing with my windows now. Presently I have Slackware Linux running connected to our LAN but it will still connect to windows for Internet. Thus, I want to replace my windows server with Slackware. Is it possible to configure VSAT with Linux?. How?. Please help me. Yes please coz I want to get rid off my windows as soon as possible.

Thanks a lot.

Begginner

Offline tomamodi

  • Linux Learner
  • ***
  • Posts: 78
hello
« Reply #11 on: August 08, 2004, 06:08:54 PM »
please i
for line in /etc/rc.d/rc.local

this line is enough    /etc/rc.d/rc.nat

or with touch  command

touch /etc/rc.d/rc.nat

still i am not succedded

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
Internet Sharing in Linux / NAT How to
« Reply #12 on: August 09, 2004, 07:22:08 AM »
well you can create directory using mkdir or also using touch then put that above script in that directory !!

Offline anil_garg5

  • Linux Learner
  • ***
  • Posts: 71
Internet Sharing in Linux / NAT How to
« Reply #13 on: August 13, 2004, 11:30:17 AM »
Nice ..really good one.

Ricky, I implement this ...working fine.

Kindly guide us ...

Thanks a lot

Offline Cytomatrix

  • New Member
  • Posts: 1
    • http://www.hellband.tk
Internet Sharing in Linux / NAT How to
« Reply #14 on: August 27, 2004, 09:40:01 AM »
If i am using slackware as my linux gateway for my windows PCs, how do i open ports for my windows. I play halo (a online game) and counter strike. How do i open ports for my windows application. Another thing, my ISP binds Mac address. If my mac address is wrong i won't able to connect to internet. I can register upto 3 mac addresses, but i can only connect one computer at a time. Will i able to use this technic to share internet.
thanks  :D