리눅스 ftp smtp 포트 특정IP 만 허용하기



iptables 로 특정아이피에서만 접근이 가능하게 하는 방법입니다.


ftp smtp mysql 포트를 127.0.0.1(localhost)과 192.168.1.1 만 허용하는 예제입니다.


iptables -I INPUT -p tcp --dport 21 -j DROP

iptables -I INPUT -s 127.0.0.1 -p tcp --dport 21 -j ACCEPT

iptables -I INPUT -s 192.168.1.1 -p tcp --dport 21 -j ACCEPT

iptables -I INPUT -p tcp --dport 25 -j DROP

iptables -I INPUT -s 127.0.0.1 -p tcp --dport 25 -j ACCEPT

iptables -I INPUT -s 192.168.1.1 -p tcp --dport 25 -j ACCEPT

iptables -I INPUT -p tcp --dport 3306 -j DROP

iptables -I INPUT -s 127.0.0.1 -p tcp --dport 3306 -j ACCEPT

iptables -I INPUT -s 192.168.1.1 -p tcp --dport 3306 -j ACCEPT

service iptables save


위와 같이 명령어를 실행하면 됩니다.


확인은 iptables -L 로 확인할 수 있습니다.


# iptables -L

Chain INPUT (policy ACCEPT)

target     prot opt source               destination

ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

ACCEPT     all  --  anywhere             anywhere

DROP       icmp --  anywhere             anywhere

ACCEPT     tcp  --  192.168.1.1          anywhere            tcp dpt:ftp

ACCEPT     tcp  --  localhost.localdomain  anywhere            tcp dpt:ftp

DROP       tcp  --  anywhere             anywhere            tcp dpt:ftp

ACCEPT     tcp  --  192.168.1.1          anywhere            tcp dpt:smtp

ACCEPT     tcp  --  localhost.localdomain  anywhere            tcp dpt:smtp

DROP       tcp  --  anywhere             anywhere            tcp dpt:smtp

ACCEPT     tcp  --  192.168.1.1          anywhere            tcp dpt:mysql

ACCEPT     tcp  --  localhost.localdomain  anywhere            tcp dpt:mysql

DROP       tcp  --  anywhere             anywhere            tcp dpt:mysql

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ftp

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:domain

ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:domain

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpts:irdmi:webcache

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:warehouse


iptables 정책은 위쪽이 우선순위가 높습니다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,