Skip to content

Instantly share code, notes, and snippets.

@JinhaiZ
Last active September 28, 2021 19:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JinhaiZ/e021be1d0dbac77e1cd2c247f5f9f012 to your computer and use it in GitHub Desktop.
Save JinhaiZ/e021be1d0dbac77e1cd2c247f5f9f012 to your computer and use it in GitHub Desktop.
Direct Ethernet connection to Raspberry Pi/Odroid without router (with DHCP, tested on Ubuntu 16.04)

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

Direct Ethernet connection to Raspberry Pi/Odroid without router

The solution is based on running DHCP service at your workstation (your notebook for example), and use it to attribute an IP address to your Raspberry Pi/Odroid. Then use ssh to connect to your Raspberry Pi/Odroid through this IP address.

Terminology Explaination
Client Your Single Board Computer, such as a Raspberry Pi or an Odroid
Server Your workstation with any linux based systems, like Ubuntu

Configuration at the Client Side (optional)

  1. Enable SSH connection
  • for Raspberry Pi
    sudo systemctl enable ssh
  • for Odroid
    sudo vim /etc/ssh/sshd_config
    find the line PermitRootLogin and set it to PermitRootLogin yes
  1. Modify DHCP Client configuration
    sudo vim /etc/dhcp/dhclient.conf
    
    fin the line send host-name "foo"; and uncommented it

Configuration at the Server Side

  1. Install a DHCP server

    sudo apt-get install isc-dhcp-server
    
  2. Use ifconfig to find your Ethernet network interface, it's probably eth0 but in my case it's enp61s0, then you need to configure a subnetwork on this interface

  3. Backup your interface configuration file

    sudo cp /etc/network/interfaces /etc/network/interfaces.original
    
  4. Modify interface configuration file

    sudo vim /etc/network/interfaces
    

    which should be modified like the output below

    auto lo
    iface lo inet loopback
    
    iface enp61s0 inet static
            address 192.168.1.1
            netmask 255.255.255.0
            network 192.168.1.0
    
    
  5. Backup your configuration file of DHCP service

    sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.original
    
  6. Modify the configuration file of DHCP service

    sudo vim /etc/dhcp/dhcpd.conf
    

    which should be modified like the output below

    ddns-update-style	none;
    default-lease-time 3600;
    max-lease-time 7200;
    authoritative;
    
    subnet 192.168.1.0 netmask 255.255.255.0 {
      option routers 192.168.1.1;
      range 192.168.1.100 192.168.1.200;
    }
    
  7. Start the DHCP service by typing

    # bring up the enp61s0 interface
    sudo ifup enp61s0 
    # start DHCP service
    sudo service isc-dhcp-server start
    # enable forwarding from the ethernet to wireless router
    sudo /sbin/iptables --table nat -A POSTROUTING -o wlan0 -j MASQUERADE
    
  8. Now plug your Raspberry Pi or or Odroid and open another terminal and tape

    tail -f /var/log/sys/log
    

    to test the connection, you should see an entry like

    Dec 3 21:51:24 jzhou-Alienware-15-R3 dhcpd[10817]: DHCPACK on 192.168.1.100 to 00:1e:06:cb:e0:f5 (foo) via enp61s0

  9. Then you can connect to your Raspberry Pi or or Odroid by

    • for Odroid ssh root@192.168.1.100
    • for Raspberry Pi ssh pi@192.168.1.100

Reference and Useful Resource

  1. ODROID-C2 from scratch
  2. How do I install and configure a DHCP server?
  3. Serveur DHCP : isc-dhcp-server
  4. Linux(非 ubuntu) 用一根网线连接树莓派
  5. Ubuntu Linux Display List of Ethernet Adapter
  6. Connecting a Raspberry Pi to a ubuntu netbook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment