debian下配置防火墙iptables
2019独角兽企业重金招聘Python工程师标准>>>
debian下iptables输入命令后即时生效,但重启之后配置就会消失,可用iptables-save快速保存配置,因为Debian上iptables是不会保存规则的,然后在开机自动的时候让iptables自动加载刚刚导出的配置文件,方法如下:
若要停止iptables,iptables -F清空所有配置效果等同于停止。
whereis iptables 查找iptables 所在的路径。
1、将iptables配置保存到/etc/iptables,这个文件名可以自己定义,与下面的配置一致即可
iptables-save > /etc/iptables
2、创建自启动配置文件,并授于可执行权限
iptables-save > /etc/iptables
3、编辑该自启动配置文件,内容为启动网络时恢复iptables配置
vi /etc/network/if-pre-up.d/iptables
内容为:
#!/bin/sh
/sbin/iptables-restore < /etc/iptables
保存并退出。这样重启之后iptables就自动加载规则了。
##注意:在下次修改iptables规则之后要重新导出配置文件。
#清空配置
iptables -F
iptables -X
iptables -Z
#配置,禁止进,允许出,允许回环网卡
iptables -P INPUT DROP
iptables -A OUTPUT -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
#允许ping
iptables -A INPUT -p icmp -j ACCEPT
#允许ssh
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#允许ftp
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
#允许ftp被动接口范围,在ftp配置文件里可以设置
iptables -A INPUT -p tcp --dport 20000:30000 -j ACCEPT
#学习felix,把smtp设成本地
iptables -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT -s 127.0.0.1
iptables -A INPUT -p tcp -m tcp --dport 25 -j REJECT
#允许DNS
iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
#允许http和https
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# 允许已建立的或相关连的通行
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#禁止其他未允许的规则访问
iptables -A INPUT -j REJECT #(注意:如果22端口未加入允许规则,SSH链接会直接断开。)
iptables -A FORWARD -j REJECT
#保存配置
iptables-save > /etc/iptables
由于Debian安装iptables后默认不是服务提示service iptables提示unrecognized service,需要添加脚本到/etc/init.d/,脚本如下
建议将其保存为/etc/init.d/iptables,然后chmod +x /etc/init.d/iptables 添加运行权限。
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: iptables
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop iptables firewall
# Description: Start, stop and save iptables firewall
### END INIT INFO
PATH=”/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin”
IPTABLES=/sbin/iptables
IPTABLES_SAVE=/sbin/iptables-save
IPTABLES_RESTORE=/sbin/iptables-restore
IPTABLES_CONFIG=/etc/iptables.conf
[ -x $IPTABLES ] || exit 0
. /lib/lsb/init-functions
case "$1" in
start)
log_action_begin_msg "Starting firewall"
type usplash_write >/dev/null 2>/dev/null && usplash_write "TIMEOUT 120" || true
if $IPTABLES_RESTORE < $IPTABLES_CONFIG ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
type usplash_write >/dev/null 2>/dev/null && usplash_write "TIMEOUT 15" || true
;;
stop)
log_action_begin_msg "Saving current firewall configuration"
if $IPTABLES_SAVE > $IPTABLES_CONFIG ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
log_action_begin_msg "Flushing ALL firewall rules from chains!"
if $IPTABLES -F ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
log_action_begin_msg "Deleting ALL firewall chains [Warning: ACCEPTING ALL PORT SERVICES!]"
if $IPTABLES -X ; then
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
log_action_end_msg $?
else
log_action_end_msg $?
fi
;;
save)
log_action_begin_msg "Saving current firewall configuration"
if $IPTABLES_SAVE > $IPTABLES_CONFIG ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
;;
force-reload|restart)
log_action_begin_msg "Reloading firewall configuration [Warning: POTENTIAL NETWORK INSECURITY DURING RELOAD]"
$IPTABLES -F
$IPTABLES -X
if $IPTABLES_RESTORE < $IPTABLES_CONFIG ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
;;
*)
echo "Usage: /etc/init.d/iptables {start|stop|save|restart|force-reload}"
exit 1
;;
esac
exit 0
转载于:https://my.oschina.net/u/2404183/blog/509676
debian下配置防火墙iptables相关推荐
- 如何在 Debian 下配置邮件服务器
本教程将讨论如何在Debian(或Ubuntu)配置一个可工作的邮件服务器.我们知道在邮件服务器使用的主要协议有SMTP.POP和IMAP.在本教程中,SMTP协议使用postfix,POP/IMAP ...
- Debian下配置SSH服务器的方法
Debian 503版本中实现的,Debian默认好像是没有ssh支持的. SSH的安装 apt-get install openssh-server apt-get install ssh SSH的 ...
- debian apache php mysql,Debian下配置APACHE2+MYSQL5+PHP5
Loading... 如果之前安装过apache, mysql, php,要先删除掉: #apt-get remove --purge apache2.2-common apache2 #apt-ge ...
- debian下配置网络 安装无线网卡驱动 Broadcom BCMXX系列
解决方案来自于debian官网 https://wiki.debian.org/wl 1.加入源 deb http://http.debian.net/debian/ wheezy main c ...
- linux添加ipv6静态路由命令,Debian下配置IPV6和静态路由
一.编辑网卡文件 vi /etc/network/interfaces 二.修改网卡文件# This file describes the network interfaces available o ...
- linux下配置防火墙
查看状态service iptables status 1) 临时生效,重启后复原 开启: service iptables start 关闭: service iptables stop 重启: s ...
- Debian 下配置ssh
SSH的安装 apt-get install openssh-server apt-get install ssh SSH的配置 OpenSSH的配置都集中在/etc/ssh/ssh_config文件 ...
- debian 下配置common lisp环境
很简单, emacs + slime + sbcl , 一条命令: # apt-get emacs slime 安装结束后, 打开emacs, alt+x 输入slime便可进入交互环境 转载于:ht ...
- Linux 防火墙配置(iptables和firewalld)
目录 防火墙基本概念 Iptables讲解 Iptables表 Iptables规则链 Iptables控制类型 Iptables命令配置 firewalld讲解 Firewalld区域概念 Fire ...
- Linux下防火墙iptables用法规则详及其防火墙配置
原博主文章更美丽: http://www.cnblogs.com/yi-meng/p/3213925.html iptables规则 规则--顾名思义就是规矩和原则,和现实生活中的事情是一样的,国有国 ...
最新文章
- 深入解析Spring MVC与Web Flow
- wpf中内容包含在border中_WPF Border各种属性介绍
- python移除系统多余大文件
- Android 顶部切换实现(二)
- android记账本统计_记账送老婆啦!初音 蕾姆 随便挑随便选| iOS 安卓
- 代码优化导致的奇葩问题
- Hadoop的安装与配置——搭建完全分布式集群
- latex参考文献BibTeX的使用方法
- 华为摄像机搜索软件_华为放大招!概念股掀涨停潮,A股全产业链名单曝光(附名单)...
- 如何高效率学习PMP?
- 多模态学习方法综述(期刊论文)
- SWA(随机权重平均)
- Linux中GoogleChrome谷歌浏览器安装好了打不开怎么办?
- @SpringBootApplication注解的意思
- 1分钟了解 rap2
- macbook air 卸载java,macbook air如何删除程序
- 数据链路层(一、二)——差错控制
- 5.4 微程序控制器
- 云授权重新定义互联网下的软件保护
- 关于PHP 动态实例化可变化类名称
热门文章
- 物联网全景动态图谱2.0|PaaS物联网平台汇总(上篇)
- 磁盘驱动属于计算机的,计算机基本知识(8005)---HDD(硬盘驱动器Hard Disk Drive)
- [经验教程]2022微信怎么给微信好友批量群发消息?
- codeforces 607B Zuma 区间dp
- github php right way,GitHub - seraph526/php-the-right-way: 收集PHP最佳实践、编码规范和权威学习指南,方便PHP开发者阅读和查找...
- 关于烂代码的那些事(下)
- windows中动态磁盘卷种类介绍
- 阴阳师维护服务器,阴阳师3月3日服务器维护更新内容公告
- 老人与海好词100英文带翻译_英文版《老人与海》小说中优美语句50句
- java计算机毕业设计民航售票管理系统源代码+数据库+系统+lw文档