I have a lot of hosts that should be allowed for ssh access for my servers,
so I prefer to use "ipfw table" for organize the list of permitted hosts.
/etc/rc.conf
Code:
firewall_enable="YES"
firewall_script="/root/scripts/rc.firewall"
/root/scripts/rc.firewall
Code:
ipfw='/sbin/ipfw -q'
${ipfw} table 22 flush
for ip in `cat /root/bin/mynetlist.db`; do
${ipfw} table 22 add $ip
done
#ssh
${ipfw} add allow tcp from 192.168.0.0/24,10.0.0.0/24 to me 22
${ipfw} add allow tcp from me 22 to 192.168.0.0/24,10.0.0.0/24
${ipfw} add allow tcp from FAILSAFE_HOST to me 22
${ipfw} add allow tcp from me 22 to FAILSAFE_HOST
${ipfw} add allow tcp from table\(22\) to me dst-port 22
${ipfw} add allow tcp from me 22 to table\(22\)
${ipfw} add deny log logamount 0 tcp from any to me 22
The plaintext file
/root/bin/mynetlist.db contains a list of permitted networks one per line, like this
Also I have a master-copy of file mynetlist.db on some remote server, and update the local file from master.
Finally, for advanced security, I enable 'AllowUsers' option of
/etc/ssh/sshd_config only for the specified low-privilege users