#!/bin/bash
NAME: ssh-setup
PATH: /mnt/e/bin
DESC: Display network details needed to setup SSH or debug after setup.
CALL: Called from terminal with sudo
permissions.
DATE: June 18, 2020. Modified: Original Version.
NOTE: When debugging script place terminal results in appropriate sections.
From: https://askubuntu.com/questions/628383/output-only-mac-address-on-ubuntu#comment892989_628387
export LANG=C # Force english names for sed search. For example in
# another language HWaddr is direcciónHW
if [[ $(id -u) != 0 ]]; then # root powers needed to call this script
echo >&2 "'$(basename $0)' must be called with 'sudo'"
exit 1
fi
Must have the nmap package.
command -v nmap >/dev/null 2>&1 || { echo >&2
"'nmap' package required but it is not installed. Aborting.";
exit 2; }
Must have the lshw package.
command -v lshw >/dev/null 2>&1 || { echo >&2
"'lshw' package required but it is not installed. Aborting.";
exit 3; }
OTHER PACKAGES CONSIDERED AND REJECTED:
$ network-test
The program 'network-test' is currently not installed. You can install it
by typing: 'sudo apt install ifupdown-extra'
Seems kind of lame and has md5 checksum error.
$ netstat | wc -l
824
Way to many lines to make use of. Might be good to track down specific addy.
$ iwconfig
wlp60s0 IEEE 802.11 ESSID:"XXXXXXXXXXXXXX"
Mode:Managed Frequency:5.22 GHz Access Point: AE:20:2E:CC:94:50
Bit Rate=6 Mb/s Tx-Power=23 dBm
Reveals router name (EESID) which is bad for neighbours to know us by....
echo
echo "Gathering system details - Will take 15 - 30 seconds"
Display () {
$1 = command that was run (sometimes abridged version if lots of seds)
$2 = output from command
echo " "
String1="========== $1 "
String2="====================================================================="
String3="$String1$String2"
echo "${String3:0:79}"
echo " "
echo "$2"
} # Display
What systemd network services are running?
NET_Service="" # Default no directory
NET_Service=$(systemctl status net)
Display 'systemctl status net' "$NET_Service"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
(ABRIDGED)
- network-online.target - Network is Online
- networking.service - Raise network interfaces
- network.target - Network
- network-pre.target - Network (Pre)
---------------------------------------------------------------------------- */
END
Is SSH systemd service (aliased as sshd) running?
SSH_Service="" # Default no directory
SSH_Service=$(systemctl status ssh)
Display 'systemctl status ssh' "$SSH_Service"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
● ssh.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
---------------------------------------------------------------------------- */
END
What SSH keys are already setup?
SSH_Keys="" # Default no directory
[[ -d ~/.ssh ]] && SSH_Keys=$(ls -al ~/.ssh |
grep -v ^total |
grep -v ^d )
# remove total line, ./ and ../ directories
Display '[[ -d ~/.ssh ]] && SSH_Keys=$(ls -al ~/.ssh)' "$SSH_Keys"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
id_rsa
id_rsa.pub
known_hosts
---------------------------------------------------------------------------- */
END
What SSH packages are currently installed?
SSH_Installed="" # Default no SSH packages
SSH_Installed=$(apt list 2>/dev/null | grep ssh | grep installed |
sed 's/ [installed.*//')
# remove [installed] & [installed, automatic] strings
Display "apt list 2>/dev/null | grep ssh | grep installed" "$SSH_Installed"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
libssh-4/xenial-updates,xenial-security,now 0.6.3-4.3ubuntu0.5 amd64
libssh-gcrypt-4/xenial-updates,xenial-security,now 0.6.3-4.3ubuntu0.5 amd64
libssh2-1/xenial-updates,xenial-security,now 1.5.0-2ubuntu0.1 amd64
openssh-client/xenial-updates,xenial-security,now 1:7.2p2-4ubuntu2.8 amd64
sshfs/xenial,now 2.5-1ubuntu1 amd64
---------------------------------------------------------------------------- */
END
What is the SSH configuration?
SSH_Config="" # Default no SSH packages
[[ -f ~/etc/ssh/sshd.config ]] && SSH_Config=$(cat ~/etc/ssh/sshd.config)
Display "cat /etc/ssh/sshd.config" "$SSH_Config"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
---------------------------------------------------------------------------- */
END
What IP address are on this machine?
LOCAL_IP_Addresses="" # Default machine has no network cards
LOCAL_IP_Addresses=$(ifconfig -a | grep -v ^' ' -A1 |
grep -v '--')
# grep to -v to remove extra lines
Display "ifconfig -a | grep -v ^' ' -A1" "$LOCAL_IP_Addresses"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
enp59s0 Link encap:Ethernet HWaddr 28:f1:0e:2a:1a:ed
inet addr:192.168.0.12 Bcast:192.168.0.255 Mask:255.255.255.0
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
wlp60s0 Link encap:Ethernet HWaddr 9c:b6:d0:10:37:f7
inet addr:192.168.0.10 Bcast:192.168.0.255 Mask:255.255.255.0
---------------------------------------------------------------------------- */
END
What IP address (potential servers/clients) are visible on network?
NET_IP_Addresses="" # Default LAN is not running
NET_IP_Addresses=$(nmap -sn 192.168.0/24 |
sed '/^Starting Nmap/d' |
sed '/^Nmap done/d' |
sed -z 's/Nmap scan report for //g' |
sed -z 's/\nHost is up./ LOCAL NETWORK CARD/g' |
sed -z 's/\nHost is up / /g' |
sed -z 's/\nMAC Address: / MAC: /g' )
sed 's/MAC.*(/(/g') # MAC makes line too long
# Use sed to remove line breaks making results lengthy
Display "nmap -sn 192.168.0/24" "$NET_IP_Addresses"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
hitronhub.home (192.168.0.1) (0.00072s latency). (Unknown)
dell (192.168.0.13) (0.00021s latency). (Dell)
dell (192.168.0.14) (0.00022s latency). (Dell)
hs100 (192.168.0.15) (0.010s latency). (Unknown)
android-47cdabb50f83a5ee (192.168.0.16) (0.0093s latency). (Hon Hai Precision Ind.)
192.168.0.254 (-0.100s latency). (Hitron Technology)
alien (192.168.0.10) LOCAL NETWORK CARD
alien (192.168.0.12) LOCAL NETWORK CARD
---------------------------------------------------------------------------- */
END
#What network cards are installed:
NetworkCards="" # Contents of /etc/hosts should contain all IP addresses on LAN
NetworkCards=$(lshw -c network | grep -Ei 'description|product|serial' |
sed 's/ description: //g' |
sed -z 's/\n product: /: /g' |
sed -z 's/\n serial: / - /g')
Display "lshw -c network | grep -Ei 'description|product|serial'" "$NetworkCards"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
Ethernet interface: Killer E2400 Gigabit Ethernet Controller - 28:f1:0e:2a:1a:ed
Wireless interface: QCA6174 802.11ac Wireless Network Adapter - 9c:b6:d0:10:37:f7
---------------------------------------------------------------------------- */
END
Email /etc/hosts file to yourself and update contents below on machine
STATIC_IP_Addresses="" # Contents of /etc/hosts should contain all IP addresses on LAN
STATIC_IP_Addresses=$(cat /etc/hosts | grep 192.168)
Display "cat /etc/hosts | grep 192.168" "$STATIC_IP_Addresses"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
192.168.0.10 alien AW 17R3 WiFi 9c:b6:d0:10:37:f7
192.168.0.12 alien AW 17R3 Ethernet 28:f1:0e:2a:1a:ed
192.168.0.13 dell Inspiron 17R-SE-7720 Ethernet 5c:f9:dd:5c:9c:53
192.168.0.14 dell Inspiron 17R-SE-7720 WiFi 60:6c:66:86:de:bd
192.168.0.15 hs100 Sony TV Wall Light
192.168.0.16 android-47cdabb50f83a5ee Sony Bravia TV KBL 50W800C
---------------------------------------------------------------------------- */
END
Firewall
Selecteend TLP stats that might prove helpful for debuggin.
ufw_stats="" # Contents of /etc/hosts should contain all IP addresses on LAN
ufw_stats=$(ufw status verbose)
Display "FIREWALL: ufw status verbose" "$ufw_stats"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
-------------- Any error messages below are coming from tlp-stat --------------
cat: /sys/class/power_supply/hidpp_battery_23/present: No such file or directory
cat: /sys/class/power_supply/hidpp_battery_24/present: No such file or directory
---------------------------------------------------------------------------- */
END
echo --------------
Any error messages below are coming from tlp-stat --------------
Selected TLP stats that might prove helpful for debuggin.
TLP_stats="" # Contents of /etc/hosts should contain all IP addresses on LAN
command -v tlp-stat >/dev/null 2>&1 &&
TLP_stats=$(tlp-stat | grep -E '^autosuspend|ENABLE|WOL')
Display "tlp-stat | grep -E '^autosuspend|ENABLE|WOL'" "$TLP_stats"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
TLP_ENABLE=1
WOL_DISABLE=Y
autosuspend = enabled
---------------------------------------------------------------------------- */
END
: <<'END'
/* ------------------ WOL (Wake On LAN) General Comments --------------------
******************* UBUNTU 16.04 *******************
From: https://askubuntu.com/questions/764158/
how-to-enable-wake-on-lan-wol-in-ubuntu-16-04
Also: http://manpages.ubuntu.com/manpages/xenial/man8/NetworkManager.8.html
In Ubuntu 16.04 set WOL_DISABLE=N in /etc/default/tlp to avoid getting WOL
disabled by TLP power management.
http://linrunner.de/en/tlp/docs/tlp-configuration.html
Add NETDOWN=no in /etc/default/halt to prevent powering off the network
card during shutdown
Enable Wake on LAN in /etc/network/interfaces when static network
configuration is used.
This file describes the network interfaces available on your system
and how to activate them. For more information, see interfaces(5).
The loopback network interface
auto lo
iface lo inet loopback
The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1
up ethtool -s eth0 wol g
Enable wake on lan in BIOS, enter the BIOS setup and look for something
called "Wake up on PCI event", "Wake up on LAN" or similar. Change it so
that it is enabled. Save your settings and reboot.
https://help.ubuntu.com/community/WakeOnLan
Warning some motherboards / network controllers don't support WOL from the
cold boot (S5 state, where the power to the system is physically turned off
and back on again). In that case, at least one power cycle (power up,
shutdown) has to be performed. To mitigate to the problem, the BIOS can be
configured to power up when AC is restored and schedule a shutdown inside
Ubuntu afterwards. Refer to the motherboard's manual for further details.
******************* UBUNTU 18.04 *******************
NOTE: In Ubuntu 18.04 /etc/network/interfaces maybe DEPRECATED
You might have to create your own script for WOL in:
/etc/NetworkManager/dispatcher.d/99-Xxxxxx
See: https://askubuntu.com/a/1111656/307523
https://wiki.archlinux.org/index.php/
NetworkManager#Network_services_with_NetworkManager_dispatcher
---------------------------------------------------------------------------- */
END
WOL from: https://wiki.debian.org/WakeOnLan
apt install ethtool
ethtool -s eth0 wol g
Above is NOT PERSISTENT across suspend/resume cycle so issue upon resume
not just boot. /etc/network/interfaces above has setup.
Archwiki: https://wiki.archlinux.org/index.php/Wake-on-LAN
apt install wakeonlan
wol target_MAC_address
From: https://www.thegeekstuff.com/2008/11/
wol-wakeonlan-guide-remotely-turn-on-servers-without-physical-access/
wakeonlan 5c:f9:dd:5c:9c:53
Do we have 'NETDOWN=no' line present for machines that shutdown"?
HaltConfig="" # Default no file
[[ -f /etc/default/halt ]] && HaltConfig=$(cat /etc/default/halt)
Display 'cat /etc/default/halt' "$HaltConfig"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
Default behaviour of shutdown -h / halt. Set to "halt" or "poweroff".
HALT=poweroff
---------------------------------------------------------------------------- */
END
Do we have static IP addresses setup?
NetworkInterfaces="" # Default no file
[[ -f /etc/network/interfaces ]] && NetworkInterfaces=$(cat /etc/network/interfaces)
Display 'cat /etc/network/interfaces' "$NetworkInterfaces"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
interfaces(5) file used by ifup(8) and ifdown(8)
/etc/network/interfaces
For Ubuntu 16.04 ONLY according to notes in ssh-setup
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1
up ethtool -s eth0 wol g
---------------------------------------------------------------------------- */
END
Hide your router address below if publishing!
nmcliConnections="" # Default no file
nmcliConnections=$(nmcli -p connection show)
Display 'nmcli -p connection show' "$nmcliConnections"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
====================================================================================
NetworkManager connection profiles
====================================================================================
NAME UUID TYPE DEVICE
Xxxx-Xxxxxx-Xx cf8fda92-0e59-4d0e-8821-cedb4be10d26 802-11-wireless wlp60s0
Wired connection 1 378122bb-ad44-3ddd-a616-c93e1bf0f828 802-3-ethernet enp59s0
Xxxxxxxxx-5G 73c40a50-0f2e-431c-b12c-e4712b3abdb4 802-11-wireless --
---------------------------------------------------------------------------- */
END
EthernetInterface=$(ifconfig -a | grep ^'e' | cut -d' ' -f1)
Display "ifconfig -a | grep ^'e' | cut -d' ' -f1"
"Ethernet Interface that could be used for WOL: $EthernetInterface"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
Ethernet Interface that could be used for WOL: enp59s0
---------------------------------------------------------------------------- */
END
What WOL_Settings exist for Ethernet Interface?
WOL_Setting="'ethtool' not installed."
command -v ethtool >/dev/null 2>&1 &&
WOL_Setting="$(ethtool $EthernetInterface | grep -i 'Wake-on:')"
Display "ethtool $EthernetInterface | grep -i 'Wake-on:'" "$WOL_Setting"
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
Supports Wake-on: pumbag
Wake-on: g
---------------------------------------------------------------------------- */
END
Display 'END OF REPORT' ""
TEST STUFF
#Spare:
: <<'END'
/* ------------ RESULTS -------------------------------------------------------
---------------------------------------------------------------------------- */
END
netplan
is not installed on Ubuntu 16.04.6 LTS by default. I could install it but I think that might open a can of worms? I've placed my static IP addresses into/etc/hosts
but I'm not sure if this is wherenetplan
places them too? – WinEunuuchs2Unix Jun 14 '20 at 18:10/etc/network/interfaces
before netplan found its way in ubuntu. And now it's something like this :/etc/netplan/01-network-manager-all.yaml
You said you want to upgrade to 20.04 and there the default option is netplan. So it can be forward-compatible to use netplan instead of the default one in 16.04. And AFAIK/etc/hosts
is just for DNS resolution ( some kind of permanent local cache). – Parsa Mousavi Jun 14 '20 at 18:23$ cat /etc/network/interfaces
is pretty sparse with: line 1:# interfaces(5) file used by ifup(8) and ifdown(8)
line 2:auto lo
line 3:iface lo inet loopback
. I think I'll savenetplan
support for the second version of the script. When I install 20.04 it will be to a new partition and I'll create the second setup script version there. – WinEunuuchs2Unix Jun 14 '20 at 18:28udev
rules perhaps. You are giving me tons of things to look at. Thank you. – WinEunuuchs2Unix Jun 14 '20 at 18:33