通常会安装防火墙,Debian上有很防火墙,Iptables为比较常用的免费防火墙,Iptables能够提供数据包过滤,网络地址转换(NAT)等功能.在Debian上手工配置Iptables的资料比较少,本文做一个详细的介绍.
第一步,首先确定你的系统已经安装Iptables.打开SSH终端,输入
第二步:查看Iptables目前的配置信息
第三步:配置Iptables 02 03 # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0 04 -A INPUT -i lo -j ACCEPT 05 -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT 06 07 # Accepts all established inbound connections 08 -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 09 10 # Allows all outbound traffic 11 # You could modify this to only allow certain traffic 12 -A OUTPUT -j ACCEPT 13 14 # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites) 15 -A INPUT -p tcp --dport 80 -j ACCEPT 16 -A INPUT -p tcp --dport 443 -j ACCEPT 17 18 # Allows SSH connections for script kiddies 19 # THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE 20 -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT 21 22 # Now you should read up on iptables rules and consider whether ssh access 23 # for everyone is really desired. Most likely you will only allow access from certain IPs. 24 25 # Allow ping 26 -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT 27 28 # log iptables denied calls (access via 'dmesg' command) 29 -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 30 31 # Reject all other inbound - default deny unless explicitly allowed policy: 32 -A INPUT -j REJECT 33 -A FORWARD -j REJECT 34 35 COMMIT
保存本文件,然后把本规则加载,使之生效,注意,iptables不需要重启,加载一次规则就成了
第四步:保存生效的配置,让系统重启的时候自动加载有效配置
注意,如果当前用户不是root,即使使用了sudo,也会提示你没有权限,无法保存,所以执行本命令,你必须使用root用户.
为了重启服务器后,规则自动加载,我们创建如下文件:
第五:其它 |