Difference between revisions of "Jetson/Remote Access"

From eLinux.org
Jump to: navigation, search
(Created the remote access page for setting up a DHCP & DNS server)
 
(Added a troubleshooting section andd made some minor changes)
Line 19: Line 19:
 
  no-resolv
 
  no-resolv
 
  # Set the local network device
 
  # Set the local network device
  interface=eth3
+
  interface=eth0
 
  # Specify IP addresses in the format: first,last,lease_time
 
  # Specify IP addresses in the format: first,last,lease_time
 
  dhcp-range=192.168.1.100,192.168.1.110,12h
 
  dhcp-range=192.168.1.100,192.168.1.110,12h
Line 30: Line 30:
  
 
Bring up the local network using the first IP address:
 
Bring up the local network using the first IP address:
  sudo ifconfig eth3 up 192.168.1.100 netmask 255.255.255.0
+
  sudo ifconfig eth0 up 192.168.1.100 netmask 255.255.255.0
  
 
Your local network should now be up & running!
 
Your local network should now be up & running!
Line 68: Line 68:
  
 
Bring up the local network using the first IP address:
 
Bring up the local network using the first IP address:
  sudo ifconfig eth3 up 192.168.1.100 netmask 255.255.255.0
+
  sudo ifconfig eth0 up 192.168.1.100 netmask 255.255.255.0
 
          
 
          
Now your device should have internet access. For example, open an SSH terminal into the device from your PC using "ssh ubuntu@tegra-ubuntu", then see if it as internet access. Note: By default the device won't ave ICMP ping service enabled, so instead of using "ping www.google.com" you can test internet access with "wget www.google.com".
+
Now your device should have internet access. For example, open an SSH terminal into the device from your PC using "ssh ubuntu@tegra-ubuntu", then see if it as internet access. Note: By default the device won't have ICMP ping service enabled, so instead of using "ping www.google.com", you can test internet access with:
 +
wget www.google.com
  
If you reboot your device &/or desktop and can no longer access 192.168.1.100 or 192.168.1.101, you can bring up the local network again from your PC using the same "sudo ifconfig eth3 up 192.168.1.100 netmask 255.255.255.0" command as earlier. And if your device can't access internet but your desktop can then run the "./share_my_internet.sh wlan0 eth0" command again. If your desktop can't access internet then remember to re-enable your desktop's GUI network manager: "sudo service networking start;  sudo service network-manager start".
+
=== Troubleshooting ===
 +
If you reboot your device &/or desktop and can no longer access 192.168.1.100 or 192.168.1.101, you can bring up the local network again from your PC using the same "sudo ifconfig eth0 up 192.168.1.100 netmask 255.255.255.0" command as earlier. And if your device can't access internet but your desktop can then run the "./share_my_internet.sh wlan0 eth0" command again. If your desktop can't access internet then remember to re-enable your desktop's GUI network manager: "sudo service networking start;  sudo service network-manager start".

Revision as of 01:16, 8 June 2014

To remotely access your device from your PC, first you need to get your PC and your device on the same local network. If you can plug your Jetson TK1 board directly into a wired ethernet router from the onboard ethernet port or plug a Wifi USB dongle / PCIe card, then this is all you need to do. The device will get a new IP address from the DHCP server in your router, and thus your PC should be able to access your device within 30 seconds or so, and the device should have access to both the PC and the internet such as to download extra software.

If you can't plug your device into your router, then it becomes more complicated because you will need to setup a small LAN network between your PC and your device. To do this, plug a single Ethernet crossover cable from your PC to your device's Ethernet port. By default, the device waits to be allocated a dynamic IP address from a DHCP server, and your PC Ethernet port probably does too. So you need to either set them both to use static IP addresses on the same subnet, or run a DHCP server on your PC to give a dynamic IP address to your device without necessarily modifying the device in any way. Running a DHCP server is harder than setting up a static IP network, but it doesn't require making any changes to your device, since it defaults to looking for a DHCP server, so let's see how to do that on your PC. There are many guides available on the web, showing how to setup a DHCP server on your Windows or Mac PC, but this page will show how to set it up on a Linux PC.

DHCP Server using the simple dnsmasq tool

Dnsmasq provides both a simple DNS name server and a simple DHCP server. To run both a DNS & DHCP server from a computer on ethernet using IP address 192.168.1.100, follow these steps (tested on Debian Wheezy KDE, Linux Mint 16 KDE and Ubuntu 12.04):

sudo apt-get install dnsmasq

If you are using NetworkManager (that is enabled by default in many graphical desktop environments like GNOME, KDE or Unity), you probably need to turn it off for now so it doesn't interfere with your local network server:

# Check if any network manager is running
ps -ef | grep -i net
# Kill any network manager that was running, using "sudo kill <pid>" or "sudo pkill <process-name>"
sudo pkill NetworkManager
sudo nano /etc/dnsmasq.conf

Copy-paste this anywhere in the file such as at the top (note: Ctrl+V means PageDown in nano, so you might want to use Shift+Insert to paste instead):

# Based on "https://wiki.debian.org/HowTo/dnsmasq":
# Stop dnsmasq reading any other files like /etc/resolv.conf for nameservers
no-resolv
# Set the local network device
interface=eth0
# Specify IP addresses in the format: first,last,lease_time
dhcp-range=192.168.1.100,192.168.1.110,12h
# Set the DNS nameserver addresses to send to the clients, such as Google DNS or OpenDNS
server=8.8.8.8
server=8.8.4.4

Restart the dnsmasq service:

sudo /etc/init.d/dnsmasq restart

Bring up the local network using the first IP address:

sudo ifconfig eth0 up 192.168.1.100 netmask 255.255.255.0

Your local network should now be up & running! To see DHCP server error messages, or see when a new computer has grabbed an IP from this DHCP server:

sudo tail -30 /var/log/syslog

Since dnsmasq is also a DNS server, you can access the device using its hostname "tegra-ubuntu" instead of the IP address "192.168.1.101". eg:

ping tegra-ubuntu

(If this doesn't work, perhaps it has been renamed to something like "tegra-ubuntu.local" instead. You can see the name using "sudo arp". Or to permanently set the name to anything you want, add a line like "192.168.1.101 tegra-ubuntu" to "/etc/hosts" with root permissions, and then dnsmasq will instantly allow you to use it instead of the IP address).

Enable NAT internet connection sharing so that the local network can access internet from the host computer's Wifi or Ethernet connection

Note: You might need to change "wlan0" (your network device that has internet) and "eth0" (you local network device that has the Jetson board) for your computer setup. Put this into a new file named "share_my_internet.sh":

#!/bin/sh
# Share one network's internet connection with another network.
# eg: If your Wifi adapter with internet is called wlan0
# and your local Ethernet adapter is called eth0,
# then run:
#    ./share_my_internet.sh wlan0 eth0
# This will only last until you reboot your computer.
sudo iptables --flush
sudo iptables --table nat --flush
sudo iptables --delete-chain
sudo iptables --table nat --delete-chain
sudo iptables --table nat --append POSTROUTING --out-interface $1 -j MASQUERADE
sudo iptables --append FORWARD --in-interface $2 -j ACCEPT
sudo sysctl -w net.ipv4.ip_forward=1

Then make that script an executable:

chmod +x share_my_internet.sh

Now you can run it, passing first the name of your internet adapter (eg: wlan0) and your local network adapter (eg: eth0):

./share_my_internet.sh wlan0 eth0

(You will need to execute this script again if you reboot your desktop computer, so you might want to add something like "~/share_my_internet.sh wlan0 eth0" to the bottom of your "~/.bashrc" login script so it gets executed automatically).

If you are using a graphical desktop environment and thus you killed NetworkManager earlier, now you should re-start NetworkManager to give you back your regular internet:

sudo service networking start
sudo service network-manager start

Bring up the local network using the first IP address:

sudo ifconfig eth0 up 192.168.1.100 netmask 255.255.255.0
       

Now your device should have internet access. For example, open an SSH terminal into the device from your PC using "ssh ubuntu@tegra-ubuntu", then see if it as internet access. Note: By default the device won't have ICMP ping service enabled, so instead of using "ping www.google.com", you can test internet access with:

wget www.google.com

Troubleshooting

If you reboot your device &/or desktop and can no longer access 192.168.1.100 or 192.168.1.101, you can bring up the local network again from your PC using the same "sudo ifconfig eth0 up 192.168.1.100 netmask 255.255.255.0" command as earlier. And if your device can't access internet but your desktop can then run the "./share_my_internet.sh wlan0 eth0" command again. If your desktop can't access internet then remember to re-enable your desktop's GUI network manager: "sudo service networking start; sudo service network-manager start".