To limit the IP addresses which sshd listens on, you just need to modify its settings within the sshd_configfile. Follow these 4 easy steps:
- First, backup the sshd_config file, then edit it with your favorite editor.
- Now, to limit the IPs sshd listens on, you need to change the ListenAddress configuration line:root@root [~]# cd /etc/ssh/
root@root [/etc/ssh]# cp sshd_config sshd_config.save
root@root [/etc/ssh]# vi sshd_config
root@root [/etc/ssh]# diff sshd_config sshd_config.save
15c15
< ListenAddress 10.0.0.1
—
> #ListenAddress 0.0.0.0 - Next, restart sshd and verify that it’s listening on the specified address:root@root [/etc/ssh]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
root@root [/etc/ssh]# netstat -anp | grep sshd
tcp 0 0 10.0.0.1:22 0.0.0.0:* LISTEN 1718/sshd - If you want sshd to listen on more than one address, then add additional ListenAddress lines to the configuration file:root@root [/etc/ssh]# diff sshd_config sshd_config.save
15,16c15
< ListenAddress 10.0.0.1
< ListenAddress 10.0.0.2
—
> #ListenAddress 0.0.0.0root@root [/etc/ssh]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
root@root [/etc/ssh]# netstat -anp | grep sshd
tcp 0 0 10.0.0.1:22 0.0.0.0:* LISTEN 1884/sshd
tcp 0 0 10.0.0.2:22 0.0.0.0:* LISTEN 1884/sshd
And there you have it!
If you enjoyed this article, then you’ll love Zalvis's Cloud Hosting platform. Turbocharge your website and get 24/7 support from our veteran team. Our world-class hosting infrastructure focuses on auto-scaling, performance, and security. Let us show you the Zalvis difference! Check out our services.