1

I messed up. I have two network cards in one machine and one in the second. I tried to connect two computers together by setting a static IP on two machines like this:

comp1:

sudo ip ad add 10.0.0.10/24 dev eth1

comp2:

sudo ip ad add 10.0.0.20/24 dev eth0

Where eth0 on comp1 was an outside line with ip 192.168.132.100
After I rebooted the comp1 I lost network connection and I cannot see the other computer comp2.
Can someone give some advice on how to set this up?

UPDATE:

Let start from the begining:
Two computers comp1 and comp2

comp1 -> two network cards
eth0 and eth1

eth0 is an outside connection:

auto lo  
iface lo inet loopback  

auto eth0  
iface eth0 inet dhcp  

Its IP is 10.140.20.20

eth1 is for cross computer connection:

auto eth1  
iface eth1 inet static  
address 10.10.0.0  
netmask 255.255.255.0  
gateway 10.140.20.20  
dns-nameservers 10.140.20.20

comp2:

auto lo  
iface lo inet loopback  

auto eth0  
iface eth0 inet static  
address 10.10.0.1  
netmask 255.255.255.0  
gateway 10.140.20.20  
dns-nameservers 10.140.20.20  

I know that this is not working but could someone pleas explain why. I had some experience with this but years ago but it looks like I'm a newbe

UPDATE2:

Since for some reason I cannot add any more comments below you answers I am just add my progress here.

So I changed everything as you guys suggested and now I can see comp1 from comp2 and comp2 from comp1 and I can see net from comp1 but what I cannot see is the net from comp2. I have enabled ipv4 forwarding but I believe there is a problem with my setup:

comp1:

auto lo  
iface lo inet loopback  

auto eth0  
iface eth0 inet dhcp  

auto eth1  
iface eth1 inet static  
address 10.10.0.10  
netmask 255.255.255.0  

comp2:

auto eth0  
iface eth0 inet static  
address 10.10.0.20  
netmask 255.255.255.0  
gateway 10.10.0.10

So I think there needs to be a connection form eth1 to eth0 on my comp1 but I don't know how to set it up. Do I need to have a static IP on eth0 (comp1)?

When I add:

auto lo  
iface lo inet loopback  

auto eth0  
iface eth0 inet dhcp  

auto eth1  
iface eth1 inet static  
address 10.10.0.10  
netmask 255.255.255.0  
up/sbin/iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -d 0/0 -j MASQUERADE

I can access outside network but when I try to download something to comp2 like geany

sudo aptitude install geany

I get:

Err http:// ....
Temporary faliour rsulting security.ubuntu.com

1
  • You have to make your changes permanent. Take a look at @serq's answer. Having said that, you might also need to disable the network-manager of gnome/KDE, since they tend to mess things up with the network configuration if you configure stuff in the interfaces file.
    – ortang
    Nov 18, 2013 at 12:56

3 Answers 3

1

when system rebooting it read netwoking init script, which get information about your network setting from /etc/network/interfaces. Edit this file and all will be ok.

2
  • in what way: my interfaces look like this : auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp
    – baxy
    Nov 18, 2013 at 12:55
  • you can use this tutorial to setup your netwok ubuntugeek.com/…
    – serg
    Nov 18, 2013 at 13:03
1

You could use something like the following in /etc/network/interfaces:

# auto-up the interface eth0
auto eth0
# set a static configuration (inet=IP4, inet6=IP6)
# use "dhcp" instead of "static" for dhcp usage
iface eth0 inet static
        address 10.0.0.10
        netmask 255.255.255.0
        # if you use no gateway comment that line out
        gateway 10.0.0.1
1

I'm going to assume Comp1 is the one connected to the internet and you want Comp2 to be able to connect also, via Comp1. A few things in your current config are going to mess this up. First, from Comp1, is this line:

address 10.10.0.0

You can't have a .0 last octet as an address with a /24 range (which is what the 255.255.255.0 netmask gets you) - and unless you really, really need them, then don't use them in general. Make this a different address - you have 254 others to choose from. Let's just go with 10.10.0.1 here.

Since you have 10.140.20.20 configured on eth0 on this machine, it will be able to use that IP address (via eth0), so your gateway statement should work.

However, this line will not work on comp2:

gateway 10.140.20.20

Comp2 has no way to know how to get to this IP address. The only thing it knows about is the /24 network you have configured. It will be able to see any other address in that range, and that is it. This gateway address is not in that range, so it can't see the gateway you have configured. In fact, with a 2 host network, the only thing it can see is the address for Comp1. Therefore you need to change this to be the IP that you specify for Comp1. Assuming the address we mention above, this entry should therefore read:

gateway 10.10.0.1

You can leave your DNS entry unchanged. Now that you have a reachable gateway, it will simply send the packets to the gateway if it does not know where the address actually is.

For this to work, Comp1 will need to be able to route packets from Comp2, which means enabling routing on Comp1. This is easy to do on the fly:

 sysctl -w net.ipv4.ip_forward=1

If you want to make that permanent you will need to add the setting to /etc/sysctl.conf.

Now, what will happen is that any packet destined for the internet, or any other unknown host for that matter on Comp2 will be sent to Comp1. Since Comp1 is now configured to route that packet, it will receive it on eth1, and pass it on to eth2.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .