-
-
Save wturnerharris/5a0353ff4841d4e039ca to your computer and use it in GitHub Desktop.
#!/bin/sh -e | |
# | |
# rc.local | |
# | |
# This script is executed at the end of each multiuser runlevel. | |
# Make sure that the script will "exit 0" on success or any other | |
# value on error. | |
# | |
# In order to enable or disable this script just change the execution | |
# bits. | |
# | |
# By default this script does nothing. | |
# Print the IP address | |
_IP=$(hostname -I) || true | |
if [ "$_IP" ]; then | |
printf "My IP address is %s\n" "$_IP" | |
fi | |
# Wait for the TV-screen to be turned on... | |
while ! $( tvservice --dumpedid /tmp/edid | fgrep -qv 'Nothing written!' ); do | |
bHadToWaitForScreen=true; | |
printf "===> Screen is not connected, off or in an unknown mode, waiting for it to become available...\n" | |
sleep 10; | |
done; | |
printf "===> Screen is on, extracting preferred mode...\n" | |
_DEPTH=32; | |
_XRES=1080 | |
_YRES=1920 | |
_GROUP=CEA | |
_MODE=16 | |
#eval $( edidparser /tmp/edid | fgrep 'preferred mode' | tail -1 | sed -Ene 's/^.+(DMT|CEA) \(([0-9]+)\) ([0-9]+)x([0-9]+)[pi]? @.+/_GROUP=\1;_MODE=\2;_XRES=\3;_YRES=\4;/p' ); | |
#printf "===> Resetting screen to preferred mode: %s-%d (%dx%dx%d)...\n" $_GROUP $_MODE $_XRES $_YRES $_DEPTH | |
tvservice --explicit="$_GROUP $_MODE" | |
sleep 1; | |
printf "===> Resetting frame-buffer to %dx%dx%d...\n" $_XRES $_YRES $_DEPTH | |
fbset --all --geometry $_XRES $_YRES $_XRES $_YRES $_DEPTH -left 0 -right 0 -upper 0 -lower 0; | |
sleep 1; | |
echo "===> Ethernet going down." | |
ifdown eth0 | |
ifconfig eth0 10.0.2.1 netmask 255.255.255.0 | |
echo "===> Configuring ethernet forwarding..." | |
sysctl -w net.ipv4.ip_forward=1 | |
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE | |
if [ -f /boot/xinitrc ]; then | |
echo "===> Linking xinitrc and starting X..."; | |
ln -fs /boot/xinitrc /home/pi/.xinitrc; | |
su - pi -c 'startx' & | |
fi | |
exit 0 |
Client /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet static
address 10.0.2.3
netmask 255.255.255.0
broadcast 10.0.2.255
gateway 10.0.2.1
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Host /etc/network/interfaces
auto wlan0
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
address 10.0.1.230
netmask 255.255.255.0
gateway 10.0.1.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Find IP/MAC address
In case you have to re-connect the WiFi to a different network and your only means is to ssh over ethernet, you might need to find out the IP and/or MAC address of the device over ethernet. While good ol arp
utility could get the job done, I ended up using another similar utility called arp-scan
, which is more robust in that it actually does the scanning and pinging directly within the utility whereas arp
can only return known addresses of devices that recently connected. You can get around that by pinging every device in the range of IP addresses on the network, but that is exhausting.
- Download arp-scan:
brew install arp-scan
- Scan the network, looking for mac addresses registered to Raspberry Pi Foundation:
arp-scan --interface=en0 --localnet | grep Raspberry
Profit!
Additional Considerations
I should also note that if you know the networking device's manufacturer, then you could search with arp
and grep for the manufacturer's prefix code, which is the first 24 bits (or the first six digits excluding the colons) of the address. This could narrow things down for you. This might mean searching for possible manufacturer codes using the IEEE registry, which shows that Raspberry Pi Foundation is registered with the b8:27:eb
.
For lines 43-49, the configuration is forwarding its network connection from Wifi, which receives the internet, to the ethernet port. The client machine needs to replace those lines with:
Both machines are configured with static addresses.