# Networking: Gentoo PC -> Fedora F12 PC, for LAN and Internet

## muadib25

Greetings!

I want to connect my newly created Gentoo DAW to a Fedora 12 PC, for file sharing and Internet purposes.

The Fedora PC has 2 NICs, where one of them is connected to the apartment's Router. 

The Gentoo PC has 1 NIC. I am using a crossover Ethernet cable for connecting them.

[UPDATE]

I changed to crossover cable, now my two machines are able to ping each other!

Here's the IPs:

PC1(Gentoo): 192.168.1.2

PC2(Fedora): 192.168.1.3       ---    PC2(Fedora) to Router IP: 192.168.0.10

Router's IP: 192.168.0.1

All I need now is for PC1 to enter the internet...

How do I proceed from this point?

Thank you  in advance!

Kle

----------

## NeddySeagoon

muadib25,

You need IP4 packet forwarding turned on on the Fedora box.

Look at /proc/sys/net/ipv4/ip_forward if thats missing, you need to rebuild the kernel.

```
echo "1" >/proc/sys/net/ipv4/ip_forward
```

will turn on forwarding if its off.

You need to add a static route on the Fedora box that sends packets from the 192.168.1.0 subnet to the router.

I've never used Fedora, so I don't know the detail of that.

----------

## muadib25

Hello!  :Smile: 

Ok, IP4 packet forwarding is ON.

I also tried "route add -net 192.168.1.0  netmask 255.255.255.0 gw 192.168.0.1 dev eth2"

where the last IP is the Router's IP. But it returns an error: SIOCADDRT: No such process

I guess 'route' command is a universal Gnu/Linux one, right?

Best Regards,

Kle

----------

## NeddySeagoon

muadib25,

Yep, route is universal but Fedora may have patched it.

The error message will have shown you the route command syntax - check your syntax.

What is the output of route on the Fedora box?

The gentoo box will also need a default static route.

----------

## muadib25

Yes, it says on 'man route' notes: "This program is obsolete. For replacement check ip route."

Now, ip route gives the following:

192.168.1.0/24 dev eth2  proto kernel  scope link  src 192.168.1.3 

192.168.0.0/24 dev eth1  proto kernel  scope link  src 192.168.0.10 

169.254.0.0/16 dev eth2  scope link  metric 1002 

169.254.0.0/16 dev eth1  scope link  metric 1003 

default via 192.168.0.1 dev eth1 

Any clues on how I should route the Gentoo box, too?

Btw, I have to say here that I am a novice in networking, but I guess that's obvious.   :Smile: 

----------

## NeddySeagoon

muadib25,

That tells me that Fedora is using iproute2, which is a more capable replacement  for route, ifconfig and friends.

Gentoo provides it too but its not the default in in the stage3 and I've never needed its new capabilities, so I don't know its syntax.

On the gentoo box, you need an IP address for the box and and a default route that points to the next hop towards the internet.

The next hop is either the fedora box or your router, depending on exactly what the fedora box does.

I'm not a network expert either. You seem to know, or are able to find out, some commands, so that moves you out of the novice bracket.

You may need to run tcpdump on the fedora box so we can see whats happening to packets from the gentoo box.

----------

## muadib25

Well, I must have done something silly, and now, whenever I re-initialize the networks ( /etc/init.d/network restart ), I don't have internet but I have LAN between the two machines. Now, when I do 'dhclient', Internet comes back, but the LAN fails...

I guess that moves me back to the novice league!   :Smile: 

I also noticed something interesting:

When I do the '/etc/init.d/network restart' command, route gives this:

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.10    *               255.255.255.255 UH    0      0        0 eth2

192.168.1.0     *               255.255.255.0   U     1      0        0 eth2

192.168.0.0     *               255.255.255.0   U     0      0        0 eth1

link-local      *               255.255.0.0     U     1002   0        0 eth2

link-local      *               255.255.0.0     U     1003   0        0 eth1

default         192.168.0.10    0.0.0.0         UG    0      0        0 eth2

When I do 'killall dhclient' and 'dhclient', route gives this:

192.168.0.0     *               255.255.255.0   U     0      0        0 eth1

default         192.168.0.1     0.0.0.0         UG    0      0        0 eth1

P.S.: If you think I shouldn't be posting all this here, please say so. I don't want to be a nuisance in the forum!

----------

## muadib25

Never mind, I fixed this last one. A config file flag was changed somehow...

So back where we were:

I let PING on Gentoo pinging Fedora, and 'tcpdump -i eth2' returns:

cpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth2, link-type EN10MB (Ethernet), capture size 65535 bytes

16:02:38.267815 ARP, Request who-has amon-thranduil tell localhost, length 28

16:02:38.267883 ARP, Reply amon-thranduil is-at 00:0b:6a:91:ef:03 (oui Unknown), length 46

16:02:38.276333 IP amon-thranduil > localhost: ICMP echo request, id 19281, seq 397, length 64

16:02:38.276423 IP localhost > amon-thranduil: ICMP echo reply, id 19281, seq 397, length 64

16:02:39.277810 IP amon-thranduil > localhost: ICMP echo request, id 19281, seq 398, length 64Last edited by muadib25 on Sun Aug 08, 2010 2:02 pm; edited 1 time in total

----------

## NeddySeagoon

muadib25,

Thats odd, lets look at what your routing table means:-

```
Destination  Gateway        Genmask        Flags Metric Ref Use Iface

192.168.0.10    *          255.255.255.255 UH       0   0   0   eth2

192.168.1.0     *          255.255.255.0   U        1   0   0   eth2

192.168.0.0     *          255.255.255.0   U        0   0   0   eth1

link-local      *          255.255.0.0     U     1002   0   0   eth2

link-local      *          255.255.0.0     U     1003   0   0   eth1

default     192.168.0.10   0.0.0.0         UG       0   0   0   eth2
```

routing rules are applied from the top of the list working downwards, the first rule mataching the packet destination is applied. So ...

from the first rule, packets for 192.168.0.10 are set to eth2. From the last rule, any packets not yet matched are set to 192.168.0.10 on eth2. So I guess that 192.168.0.10 is the IP of your router.

The second rule says that all packets for the 192.168.1.0/24 network are sent over eth2. Thats odd, I would have expected that to be eth1, if thats where your gentoo box is. the third rule says all packets for the 192.168.0.0/24 network are sent over eth1.

Given that the default rout is over eth2, I think rules 2 and 3 point to the wrong interfaces.

The link-local entries can be ignored.

----------

## muadib25

These are Fedora's ETHx devices:

Eth0--> Doesn't exist

Eth1 --> Fedora to Router

Eth2--> Fedora to Gentoo

Btw, Fedora's ROUTE outputs the following:

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     *                    255.255.255.0   U     0      0        0        eth2

192.168.0.0     *                   255.255.255.0    U     0      0        0        eth1

link-local      *                      255.255.0.0        U     1002   0        0      eth2

link-local      *                      255.255.0.0        U     1003   0        0     eth1

default         192.168.0.1     0.0.0.0                 UG    0      0        0     eth1

And Gentoo's ROUTE outputs this:

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0      *                       255.255.255.0   U     0      0        0    eth0

loopback          *                      255.0.0.0            U     0      0        0     lo

----------

## NeddySeagoon

muadib25,

And Fedora works to the internet and the Gentoo box and Gentoo can reach the Fedora box but no further.

Gentoo now needs a default route, so it knows how to deal with packets that do not match 192.168.1.0/24

The gw will either be the IP of your fedora box, that is connected to Gentoo or your router, I'm not sure.

I guess that your gentoo /etc/resolv.conf is empty?

It needs to be the same as the fedora /etc/resolv.conf as that is what makes name resolution work.

```
ping 209.85.229.147
```

and 

```
ping goolge.com
```

do exactly the same thing but the latter needs the name resolution step.

When you test, test with both.

----------

## muadib25

For starters, I don't know what exactly to type as a ROUTE command on the Gentoo box...

is '"route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.0.10 dev eth0"' correct?

192.168.0.10  is  Fedora's IP on eth1

192.168.0.1   is Fedora's Gateway.

and

192.168.1.3 is Fedora's IP on eth2.

----------

## muadib25

I did on Gentoo  'route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.1.3 dev eth0'.

Now I can ping the router!!     :Smile: 

Resolv.conf is the same on both machines, however Gentoo still can't see the world...

Gentoo's ROUTE says:

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     *               255.255.255.0               U      0        0        0    eth0

192.168.0.0     *               192.168.1.3                  UG     0       0         0    eth0

loopback         *               255.0.0.0                        U      0        0        0     lo

----------

## muadib25

I think I did it!

I edited /etc/conf.d/net and added the line:

routes_eth1=( "default via 192.168.1.3" "10.0.0.0/8 via 192.168.1.3" "::/0")

The thing is that I just found them commented inside the '/etc/conf.d/net' file...

So, from the Gentoo side everything is ok! I can see both the Fedora PC and he router, and I can ping Google.

I keep having some problems with Fedora, though, propably something I did before. Whenever I boot, I have to 'killall dhclient', 'dhclient', and 'ifup eth2' for everything to work...So I think I will have to put these in a script at boot, or ask the Fedora forum about it...

----------

## Hu

Could you provide the output of ip route show on the Fedora machine both before and after your sequence of killing and restarting the DHCP client?  My guess is that the way you have configured it is mangling the routes, and that resetting dhclient causes it to fix the routes.  It may also be helpful if you can provide the contents of the Fedora network configuration file (their counterpart to /etc/conf.d/net).

Though we can try to help you here, you might have faster luck with the Fedora forum.  At this point, your problem has simplified down to getting a Fedora-based home router to serve both Internet and LAN at once.  If you ask on the Fedora forum for help, be sure to mention home router somewhere in the problem description.  That will likely draw the attention of the people most qualified to help you.

----------

## bus_drivr

After puzzling thru this it is unclear to me if you should ipforward or bridge. Either would work I think.

so Gentoo is on eth2 and Fedora and the gw are on eth1? and eth0 doesn't exist?

if so Fedora is going to need to bridge or forward to eth1 the Gentoo packets to/from eth2 

Seems a mess unless one is on a DMZ or firewalling/proxying the other. In that case seems better to let the router/gw handle it

----------

## muadib25

Absolutely! Thank you for the help.

First of all, the sequence is: 'killall dhclient', 'dhclient', 'ifup eth1', 'ifup eth2'.

Secondly, 'ip route show' gives this before:

192.168.1.0/24 dev eth2  proto kernel  scope link  src 192.168.1.1 

192.168.0.0/24 dev eth1  proto kernel  scope link  src 192.168.0.10  metric 1

and after the killing-resurrecting sequence:

192.168.1.0/24 dev eth2  proto kernel  scope link  src 192.168.1.3 

192.168.0.0/24 dev eth1  proto kernel  scope link  src 192.168.0.10 

169.254.0.0/16 dev eth2  scope link  metric 1002 

169.254.0.0/16 dev eth1  scope link  metric 1003 

default via 192.168.0.1 dev eth1 

So, I have to find a way to make these permanent, I guess...

About the Fedora-style /etc/conf.d/net, these are oriented per-device, '/etc/sysconfig/network-scripts/ifcfg-eth1':

DEVICE=eth1

BOOTPROTO=dhcp

HWADDR=00:E0:7D:B8:A7:D1

ONBOOT=yes

TYPE=Ethernet

NM_CONTROLLED=yes

USERCTL=yes

GATEWAY=192.168.0.1

IPV6INIT=no

DEFROUTE=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

NAME="System eth1"

UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

PEERDNS=yes

PEERROUTES=yes

and '/etc/sysconfig/network-scripts/ifcfg-eth2':

DEVICE=eth2

IPADDR=192.168.1.3

BOOTPROTO=static

NETMASK=255.255.255.0

TYPE=Ethernet

HWADDR=00:01:29:F2:7F:1F

NETWORK=192.168.1.0

BROADCAST=192.168.1.255

NM_CONTROLLED=yes

IPV6INIT=no

ONBOOT=yes

GATEWAY=192.168.0.10

USERCTL=yes

DEFROUTE=yes

NAME="System eth2"

UUID=3a73717e-65ab-93e8-b518-24f5af32dc0d

PREFIX=24

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

As for my home Router, it is an external Cisco. Sorry if you understood otherwise, all I want to achieve here is for my Fedora box to be as a Gateway for my Gentoo box, because the router is 15 meters away, and I already have one cable coming from there!

Best regards,

Kle

----------

## Hu

Regarding the route output, that confirms my suspicion that resetting dhclient causes it to clean up the routes.  If you configure the Fedora system not to start the eth2 NIC at all and then reboot, do the Internet-related routes get set correctly?  If so, I would suspect that there is some ordering issue causing the bringup of eth2 to remove critical routes that dhclient added for eth1.

 *bus_drivr wrote:*   

> After puzzling thru this it is unclear to me if you should ipforward or bridge. Either would work I think.

 Yes, either will work in this case.  Since forwarding is less disruptive to the system doing the forward, and he is already partly down that path, continuing with setup for that would be simplest.

 *muadib25 wrote:*   

> As for my home Router, it is an external Cisco. Sorry if you understood otherwise, all I want to achieve here is for my Fedora box to be as a Gateway for my Gentoo box, because the router is 15 meters away, and I already have one cable coming from there!

 No, you misunderstood my guidance.  :Smile:   Linux is perfectly capable of serving as a gateway device routing traffic between a private LAN and the public Internet.  Most documents that describe how to do this refer to such a setup as a "Linux home router."  Even though you have a Cisco device serving that purpose, the topology and the principles still apply here.  The Fedora machine is meant to serve as the Linux home router, and the Gentoo machine is part of the "private LAN" of that design.  Hence, I suggested that you be sure to characterize your problem as an issue getting a working "Linux home router" setup, since that should concisely explain to readers what you are trying to do.

----------

## muadib25

 *Quote:*   

>  If you configure the Fedora system not to start the eth2 NIC at all and then reboot, do the Internet-related routes get set correctly?

 

Yes, they do! 'route ip' shows:

192.168.1.0/24 dev eth2  proto kernel  scope link  src 192.168.1.1 

192.168.0.0/24 dev eth1  proto kernel  scope link  src 192.168.0.10  metric 1 

default via 192.168.0.1 dev eth1  proto static

Also, the Fedora box can ping the Gentoo box, but not the opposite. The Gentoo box in this case is networkless.

----------

## Hu

That is weird.  Either you did not shut off the eth2 startup completely or the Fedora scripts are doing something odd.  The eth2 interface should have been down, had no address, and therefore no routes associated with the eth2 network.

----------

## muadib25

True. Anyway, I'll try to read more into Fedora Networking, just in case I'm missing something (and I am sure I am, LOL)

I'll get back to it with more news to share.

----------

