LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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


Reply
  Search this Thread
Old 02-03-2011, 06:37 PM   #1
redss
Member
 
Registered: Jun 2003
Posts: 168

Rep: Reputation: 16
Can't set default gateway to different subnet


What am I doing wrong here?
This is slackware 12. I'm trying to share my internet connection (on eth0) with a computer connected to eth1.

eth0 is 192.168.0.101, eth1 is 192.168.1.100 (different subnets).

But when I try to make eth1's default gateway the same as eth0's, see the error I get:
Code:
# route add default gw 192.168.0.1 dev eth1
SIOCADDRT: No such process
This is supposed to work, per http://lindesk.com/2007/04/internet-...sing-iptables/

more informational output follows....
Code:
# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:07:E9:5C:77:81  
          inet addr:192.168.0.101  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1

eth1      Link encap:Ethernet  HWaddr 00:08:C7:E6:F2:04  
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth1
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0
loopback        *               255.0.0.0       U     0      0        0 lo
default         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
 
Old 02-03-2011, 07:25 PM   #2
marco18
Member
 
Registered: Jul 2007
Location: Argentina
Distribution: Ubuntu 13.04 , Debian Lenny 5.0.7
Posts: 223

Rep: Reputation: 21
As far as I am concerned, you won't be able to share your internet connection by setting that default gateway on the same machine that is directly connected to the internet. You have to set a proxy to redirect everything that comes from eth1 to eth0.

Some time ago, I used the following script. Give it execution permissions and change the extension if you like. It is configured with eth0 as the directly connected to internet interface and eth1 as the internal interface.

Just execute it and then see if the host machine nats correctly. Don't forget to set ip addresses as this script won't do anything about it.

Hope it helps!
Attached Files
File Type: txt iptablesconf.txt (2.1 KB, 45 views)
 
Old 02-03-2011, 10:37 PM   #3
redss
Member
 
Registered: Jun 2003
Posts: 168

Original Poster
Rep: Reputation: 16
That script did the trick. Thanks!
 
Old 02-04-2011, 05:05 AM   #4
redss
Member
 
Registered: Jun 2003
Posts: 168

Original Poster
Rep: Reputation: 16
Question: Would it be possible for the script to be modified to share the internet connection on eth0 with the TWO ports I have? (eth1 and eth2)

Thanks!
 
Old 02-04-2011, 12:22 PM   #5
marco18
Member
 
Registered: Jul 2007
Location: Argentina
Distribution: Ubuntu 13.04 , Debian Lenny 5.0.7
Posts: 223

Rep: Reputation: 21
Quote:
Originally Posted by redss View Post
Question: Would it be possible for the script to be modified to share the internet connection on eth0 with the TWO ports I have? (eth1 and eth2)

Thanks!
I've made some modifications to the script. Defined new variable INIF2=eth2 and then replicated iptables redirection sentences with that interface. I am unable to test it since I'm running windows now, so try it and review the script in case I made a mistake.
Attached Files
File Type: txt iptablesconf2.txt (2.3 KB, 29 views)
 
Old 02-04-2011, 09:09 PM   #6
redss
Member
 
Registered: Jun 2003
Posts: 168

Original Poster
Rep: Reputation: 16
Thanks! I will test it when I have a chance...hopefully over the next few days,,,
 
Old 02-08-2011, 02:45 PM   #7
redss
Member
 
Registered: Jun 2003
Posts: 168

Original Poster
Rep: Reputation: 16
I tested the script for 2 ports and it works like a charm!

One question: say for example the PC on the nat'd LAN port (eth1) has an telnet service running on port 21 that I want to hit from the server (on the other side of the firewall)

What would be the iptables syntax to expose port 21?
 
Old 02-09-2011, 06:52 AM   #8
marco18
Member
 
Registered: Jul 2007
Location: Argentina
Distribution: Ubuntu 13.04 , Debian Lenny 5.0.7
Posts: 223

Rep: Reputation: 21
Quote:
Originally Posted by redss View Post
I tested the script for 2 ports and it works like a charm!

One question: say for example the PC on the nat'd LAN port (eth1) has an telnet service running on port 21 that I want to hit from the server (on the other side of the firewall)

What would be the iptables syntax to expose port 21?
If you take a look at the script, you'll see at the beginning that there are two variables "puertosTCP" and "puertosUDP". Uncomment them and set there the ports you need (separated with spaces). Then, again in the script, there is the following coding:

Code:
for puerto in $puertosTCP
do
iptables -A FORWARD -i $EXIF -o $INIF -p tcp --dport $puerto -j ACCEPT || fail=1
iptables -t nat -A PREROUTING -i $EXIF -p tcp --dport $puerto -j DNAT --to $pc2:$puerto || fail=1
done

for puerto in $puertosUDP
do
iptables -A FORWARD -i $EXIF -o $INIF -p udp --dport $puerto -j ACCEPT || fail=1
iptables -t nat -A PREROUTING -i $EXIF -p udp --dport $puerto -j DNAT --to $pc2:$puerto || fail=1
done
$INIF is your internal interface (server) and EXIF is the one connected to the internet. Just change the values of the variables and you are good to go =)
 
  


Reply



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
default gateway on different subnet Joydeep Bakshi Linux - Networking 3 01-09-2010 02:17 AM
How to set (or delete) default gateway at boot? colucix VectorLinux 6 07-05-2009 03:15 PM
Default gateway not being set when using DHCP ret602 Linux - Networking 1 09-20-2007 12:17 PM
How to set default gateway Harlin Linux - Networking 2 02-28-2006 03:17 AM
How can I tell what my default gateway is currently set as? abefroman Linux - Networking 6 09-10-2005 12:15 PM

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

All times are GMT -5. The time now is 02:34 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