Monthly Archives: December 2019

Pfsense Host listing to bash auto-complete

Setup a daily cron tab as root (sudo crontab -e) to login to pfsense and grab your listing of hosts.

@daily /usr/bin/scp root@firewall.com:/etc/hosts /dev/stdout | grep ^10. | awk ‘{print $2}’ | tr A-Z a-z > /data/network_devices.txt

Next lets edit our personal bashrc file to perform host name auto-completing using the list of host names in the file:

vi .bashrc

Add the following at the bottom of the file:

#Perform auto-complete for the following commands:
complete -W “$(cat /data/network_devices.txt;)” telnet
complete -W “$(cat /data/network_devices.txt;)” ssh
complete -W “$(cat /data/network_devices.txt;)” ping
complete -W “$(cat /data/network_devices.txt;)” traceroute
complete -W “$(cat /data/network_devices.txt;)” dig
complete -W “$(cat /data/network_devices.txt;)” scp

#Optional – create an alias to update all your screen sessions:
alias update-screen=”screen -X at # stuff \”source ~/.bashrc\n\””

Lastly, change to root, generate ssh keys if you don’t already have them created, copy the keys up to your pfsense firewall

sudo -s -H -u root
ssh-keygen
ssh-copy-id root@firewall.com

Reload your personal bashrc file and you are all set:
source ~/.bashrc