# connecting to an ip masq subnet

## gooselive

I'm unable to resolve how to connect my gentoo box to the internet.

My configuration is as follows:

Connection to the internet from an external wireless access point (I have no physical access) on subnet 192.168.0.1

This computer's ip address is 192.168.0.130 on wireless nic eth1. The wired connection, eth0 is connected to my local router at subnet 192.168.1.100 and set up in the internal firewall zone with ip masquerading to the external  internet zone.

An XP box connected to my router at 192.168.1.101 can now connect to the internet by specifying 192.168.0.130 as the gateway and 192.168.0.1 as the domain name server.

I would like to configure the gentoo box in the same way, but it seems I can only ping the gateway (192.168.0.130) and the wired nic on both the masqueraded machine (192.168.1.100) and gentoo box (192.168.1.102), but no other addresses on either subnet.

Can I do this with the correct settings in /etc/conf.d/net and /etc/resolv.conf, or am I missing something?

/etc/resolve.conf:

nameserver 192.168.0.1

/etc/conf.d/net

config_eth0=( "192.168.1.102/16" )

route_eth0=( "default via 192.168.0.130" )

----------

## erik258

goosilive, you're doing well.  Your theory is sound and you are close to a working system.  

First I want to make sure I understand you.  I take from what you wrote these 3 things:

1) you have a gateway at 192.168.1.100 and 192.168.0.130.  

2) your windows box at 192.168.1.101 can talk to the world. 

3) your gentoo box at 192.168.1.102/16.  

Right? Well, if I followed you, prepare for your solution.  

Given #1, and that the router's working, I can assume that both 192.168.1 and 192.168.0 are /24 subnets; the subnet boundary must be after the 3rd octet (1 and 0, respectively) because if it were before that octet (eg a /16) 192.168.0.130 and 192.168.1.100 would be on the same subnet.  Follow? 

Incidentally, 192.168.0.1 is not a subnet.  Subnets must leave at least a few bytes to specify different host addresses.  Typical subnets for the RFC1918 Class C group 192.168.X.X  are /24 (in other words 255.255.255.0) leaving 253 host names available (0 and 255 are reserved).  192.168.0.1 is the default route for the 192.168.0.0/24 network presumably.  Make sense?

Well, most oses, even Windoze, will automatically give interfaces a /24 subnet mask for 192.168.X.X-addressed interfaces, because they are specified as Class C, or /24, subnets.  Windows probably did so.  

However, you didn't give Gentoo a chance to choose the subnet for you.  You have specified a /16 subnet specifically.  This means that the Gentoo box thinks 192.168.0.130 is on the same broadcast domain as 192.168.1.102, and therefore cannot route to the 192.168.0.0/24 subnet nor talk to 192.168.0.1 (which is not actually broadcastable).  This setup isn't technically wrong, but it's incompatible with the subnets on the other boxes.  

I hope that helped.  I can't be as clear when I'm typing as I can face to face I think.  

So, in short, you should change the gentoo box's subnet to /24, or 255.255.255.0.  You'll then have to give it a default route it can reach in one hop - something on a subnet it's on too, or to be precise, the other side of your router, 192.168.1.100.  The gentoo box doesn't need to know about the 192.168.0. subnet.  It can reach 192.168.0.1, the nameserver, just as it can reach external internet hosts, through the default route.  

So try:

```

/etc/conf.d/net

config_eth0=( "192.168.1.102/24" ) # note the change from /16 to /24

route_eth0=( "default via 192.168.1.100" ) # an address the 192.168.1/24 route created automatically can reach.  

```

----------

## devilheart

if a linux box has to do some routing you must enable ip routing with 

```
sysctl -w net.ipv4.ip_forward=1
```

 or change the line in /etc/sysctl.conf

----------

## erik258

That's true, but it's already done, as evidenced by the router's routing of traffic from the windows box.

----------

## devilheart

gooselive, your setup is not very clear. what is the netmask on windows? could you explain better the layout of your network (computers, routers, ip addresses, ...)?

----------

## gooselive

Thanks all.

I updated my configuration as recommended, but now the external subnet (192.168.0.xxx/24) returns 'connect: network is unreachable' and I can successfully ping only the addresses of the Gentoo and Suse (the shared internet connection) machines, not the XP client.

BTW, the local router on subnet 192.168.1 is still configured for automatic configuration via DHCP. The XP client doesn't seem to care, but I wonder if the Linux client requires me to make son changes. The router is a Linksys WRT54G.

----------

## gooselive

The XP firewall configuration was preventing me from pinging the XP address from the Linux boxes, so I just need to determine why the Gentoo is unable to communicate with the shared connection on the 192.168.0

----------

## gooselive

I now have internet connectivity, but have to manually add the gateway  route  from a root shell as follows:

joeler@macse ~ $ su

Password: 

 # netstat -nr

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

127.0.0.0       0.0.0.0         255.0.0.0       U         0 0          0 lo

# /sbin/route add -net 0.0.0.0  gw 192.168.1.100 eth0

# netstat -nr

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

127.0.0.0       0.0.0.0         255.0.0.0       U         0 0          0 lo

0.0.0.0         192.168.1.100   0.0.0.0         UG        0 0          0 eth0

----------

## gooselive

Due to 'route_eth0' instead of  'routes_eth0' in the /etc/conf.d/net.

----------

