Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've got a machine I control running Ubuntu 12.10. I'm on a network that will only allow me to have one device connected. I've also got a USB ethernet adapter. I'd like to create a private network hung off that for eg my Raspberry Pi so I can SSH it and it can access the internet.

Can someone please explain the concepts of what I need to do in order to achieve this without mucking up my main network connection? Not knowing exactly what it is I need to do in the vast field of linux routing has made googling somewhat futile.

share|improve this question
    
Just putting the interface on the same network as the other device is enough to access it. –  jordanm Feb 13 '13 at 13:44
    
I think Only allow certain outbound traffic on certain interfaces covers it. Is it clear enough and does it provide enough information? If not, please edit your question to say what you want explained. –  Gilles Feb 13 '13 at 23:17
add comment

1 Answer

up vote 1 down vote accepted

It depends on the exact constraints your LAN connection places on you.

If you can only connect one physical device to the network (you are only able to get one IP address - probably based on the MAC address of your network adapter), the solution you are looking for is NAT, which creates a private network and gives its nodes some degree of access (and ability to be accessed) from the outside.

The "pure software" solution in Linux would involve:

  • allowing packet forwarding between different interfaces (which is off by default)

  • setting up the NAT itself using Netfilter or more precisely its part, the iptables.

  • configuring routing for the internal network - either statically or via DHCP most likely with the DHCP server running on the machine with LAN connection. This is to ensure that

    1. the machine connected to the external network knows what to do with packets that are targeted into the private network, and
    2. the nodes on the internal network know where to send packets for the external network.

    This includes setting nameservers correctly (propagating the settings from the LAN, unless you'd want to run your own DNS server - which for one R-Pi is a bit of overkill).

keywords: NAT, iptables, packet forwarding, routing, DHCP, DNS

These first two links I have found (with the first two keywords together) seem to be reasonable.

Of course you can save yourself the trouble of setting this up by buying a home-grade router (starting at roughly a third of the price of a R-Pi). For about the price of the R-Pi, you can get a wireless router.

Now if you are allowed to connect more devices but have only one physical connector, you can set up bridging/forwarding. You would either need to create a bridge containing the two network devices in your PC, or set up packet forwarding and if your LAN uses DHCP (most networks today do) also DHCP relaying. The second option (forwarding) however doesn't make that much sense, since it actually mimics the former (i.e. bridging). There might be some reasons for choosing it, though (for example if you were connected to the network through wi-fi, bridging would be pretty much out of question).

keywords: (network) bridge, packet forwarding, DHCP relay

Again, you can use a hardware switch to the same effect. While these are cheaper than routers, the added value of a router (which can be configured to act just as a switch anyway) makes it usually a better choice.

share|improve this answer
    
As it turns out, all I needed to do was to use ubuntu's built in "share connection" setting on the second interface and assign the pi a sensible ip address fitting inside the routing entry for the interface. –  TimD Feb 15 '13 at 12:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.