allow ips to access server on port

Vijay Kumar Gajula
Vijay Kumar Gajula used Ask the Experts™
on
Dear All,

Can any one let me know how to allow only few IPs to access a particular port on Debian server?  Other IPs should be blocked.

Thanks,
Vijay.G
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
RaghavIT Specialist

Commented:
You can use "iptables" to do this.

https://www.garron.me/en/bits/iptables-open-port-for-specific-ip.html

--Raghav.

Author

Commented:
Thanks for the response, these changes are going once i restart the server. Is there any possibility to save these rules permanently.
Please let me know.
Thanks,
Vijay
IT Specialist
Commented:
1. Add the rules to the iptables and then issue below command -

iptables-save > /etc/iptables.conf      ---- This will save the rules to this configuration file.

2. Then add this command to /etc/rc.local to reload the rules on every reboot -

iptables-restore < /etc/iptables.conf

But adding anything extra to rc.local is generally a bad idea. Instead you can install and use a debian package called "iptables-persistent"

Hope this helps.

--Raghav.

Author

Commented:
thanks for the solution
RaghavIT Specialist

Commented:
You Welcome.

--Raghav.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial