1)如果只是简单的实现上网功能,很容易实现, 先配置你的网卡IP,0为你外网IP(比如:60.0.0.1),1内网地址(比如:192.168.1.1)
linux防火墙配置ip段 linux防火墙配置文件在哪
linux防火墙配置ip段 linux防火墙配置文件在哪
2) echo 1 > /proc/sys/net/ipv4/ip_forward
{#vi /etc/sysctl.conf
net.ipv4.ip_forward = 1}
3)、打开iptables的NAT功能:
/in/iptables -t nat -A POSTROUTING -o 0 -j MASQUERADE
说明:上面的语句中0是连接外网或者连接Internet的网卡. 执行下面的命令,保存iptables的规则: serv iptables se
4)、查看路由表:
netstat -rn 或 route -n
5)、查看iptables规则:
iptables -L
1.将linux主机变成路由器
#echo "1" > /proc/sys/net/ipv4/ip_forward
2.启动防火墙实现NAT
(如果是ADSL上网)
#iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
(如果只能在1的电脑上,而不许以后的2、3上网,用下面语句)
#iptables -t nat -A POSTROUTING -i 1 -o ppp0 -j MASQUERADE
(如果是静态IP上网)
#iptables -t nat -A POSTROUTING -i 1 -o 0 -j SNAT --to-source 外网IP
3.客户机将自己上网设为linux的1的IP
关注中
linux系统安装完成后启动网卡会自动获取一个ip。
如果需要静态ip,则需要用vim 编辑器修改配置文件,重启网络后生效。
#vim /etc/sysconfig/network-script/ifcfg-0
然后对网卡文件修改
DEVICE=0 #物理设备名
IPADDR=192.168.1.100 #IP地址
NETMASK=255.255.255.0 #掩码值
NETWORK=192.168.1.0 #网络地址(可不要)
BROADCAST=192.168.1.255 #广播地址(可不要)
GATEWAY=192.168.1.1 #地址
ONBOOT=yes # [yes|no](时是否激活设备)
USERCTL=no #[yes|no](非root用户是否可以控制该设备)
BOOTPROTO=static #[none|static|bootp|dhcp](时不使用协议|静态分配|BOOTP协议|DHCP协议)
很简单的,首先保证你的虚拟机软件的连接方式要是桥接方式,这是前提。不然你后边不用看了。其次:其实你上边已经作成功一半了,你就将linux下的IP地址填写和真实物理主机同个IP段的IP地址,和dns一样就行了。
就这么简单的,试试吧,祝你顺利
打开LINUX 控制台i ,切换成ROOT账户,
UBUNTU是 sudo -s -H,
redhat su = root,
然后输入命令ifconfig 0 [IP地址] netmask [255.255.255.0]
打个命令 serv iptables stop 关闭防火墙,一般来说UNBUNTU是自动默认关闭防火墙的
在这里楼主先了解一下虚拟机的连接方式1.NAT(网络地址转换,虚拟机可以上网,但不能和物理机通信)-----VMnet82.host
only(主机模式,虚拟机之间可以通信,与物理机不能
1、首先需要在Linux系统中查找并打开文件以编辑和配置防火墙,执行命令: vi /etc/sysconfig/iptables。
2、然后将以下语句添加到上面打开的文件中:-A INPUT -m state -state NEW -m tcp -p tcp -dport 80 -j ACCEPT(允许端口80通过防火墙,这里以端口80为例)。
请注意,上述语句不会加载文件的一面,这将导致防火墙无法启动。 应将正确的一个添加到默认的22端口规则中。
3、配置防火墙规则
# Manual customization of this file is not recommended.
4、重启防火墙,使配置生效。
/etc/init.d/iptables restart或者serv iptables restart
重启如下:
扩展资料:
查看防火墙规则是否生效:
[root@localhost bin]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
准备装有Linux系统的电脑。
1.在linux系统里面找到并打开编辑配置防火墙的文件,执行命令:
2.在上面打开的文件里面加入一下语句:
3.重启防火墙使配置生效语句serv iptables restart。
4.查看防火墙规则是否生效。
扩展资料:
查看防火墙状态:
[root@cluster1 ~]# serv iptables status
iptables:未运行防火墙。
开启防火墙:
[root@cluster1 ~]# serv iptables start
关闭防火墙:
[root@cluster1 ~]# serv iptables stop
Linux下开启/关闭防火墙命令
1、性生效,重启后不会复原。
开启: chkconfig iptables on
关闭: chkconfig iptables off
2、 即时生效,重启后复原
开启: serv iptables start
关闭: serv iptables stop
需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭作。
扩展资料
linux配置防火墙规则:
1、在Linux系统中查找并打开文件以编辑和配置防火墙,执行命令。: vi /etc/sysconfig/iptables。
2、将以下语句添加到上面打开的文件中:-A INPUT -m state -state NEW -m tcp -p tcp -dport 80 -j ACCEPT(允许端口80通过防火墙,这里以端口80为例)。
请注意,上述语句不会加载文件的一面,这将导致防火墙无法启动。 应将正确的一个添加到默认的22端口规则中。
3、配置防火墙规则
# Manual customization of this file is not recommended.
4、重启防火墙,使配置生效。
/etc/init.d/iptables restart或者serv iptables restart
重启如下:
1、在Linux系统中查找并打开文件以编辑和配置防火墙,执行命令。: vi /etc/sysconfig/iptables。
2、将以下语句添加到上面打开的文件中:-A INPUT -m state -state NEW -m tcp -p tcp -dport 80 -j ACCEPT(允许端口80通过防火墙,这里以端口80为例)。
请注意,上述语句不会加载文件的一面,这将导致防火墙无法启动。 应将正确的一个添加到默认的22端口规则中。
3、配置防火墙规则
# Manual customization of this file is not recommended.
4、重启防火墙,使配置生效。
/etc/init.d/iptables restart或者serv iptables restart
重启如下:
扩展资料:
查看防火墙规则是否生效:
[root@localhost bin]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
参考资料:
1、在linux系统里面找到并打开编辑配置防火墙的文件,执行命令: vi /etc/sysconfig/iptables。
2、在上面打开的文件里面加入一下语句: -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火墙,这里以80端口为例)。
注意的是上面这条语句不要加载文件的面,这样会导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面。
3、设置防火墙规则
# Manual customization of this file is not recommended.
4、重启防火墙使配置生效
/etc/init.d/iptables restart或者serv iptables restart
重启如下:
扩展资料:
查看防火墙规则是否生效:
[root@localhost bin]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
RedHat机器
一、Linux下开启/关闭防火墙命令
1、性生效,重启后不会复原。
开启: chkconfig iptables on
关闭: chkconfig iptables off
2、 即时生效,重启后复原
开启: serv iptables start
关闭: serv iptables stop
需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭作。
在当开启了防火墙时,做如下设置,开启相关端口,
修改/etc/sysconfig/iptables 文件,添加以下内容:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
二、UBuntu关闭防火墙
iptables -A INPUT -i ! PPP0 -j ACCEPT
三、CentOS Linux 防火墙配置及关闭
执行”setup”命令启动文字模式配置实用程序,在”选择一种工具”中选择”防火墙配置”,然后选择”运行工具”按钮,出现防火墙配置界面,将”安全级别”设为”禁用”,然后选择”确定”即可.
或者用命令:
#/in/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
#/in/iptables -I INPUT -p tcp –dport 22 -j ACCEPT
#/etc/rc.d/init.d/iptables se
这样重启计算机后,防火墙默认已经开放了80和22端口
这里应该也可以不重启计算机:
#/etc/init.d/iptables restart
关闭防火墙服务即可:
查看防火墙信息:
#/etc/init.d/iptables status
关闭防火墙服务:
#/etc/init.d/iptables stop
配置firewalld-cmd
查看版本: firewall-cmd --version
查看帮助: firewall-cmd --
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-intece=0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
那怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent
调整默认策略(默认拒绝所有访问,改成允许所有访问):
firewall-cmd --permanent --zone=public --set-target=ACCEPT
firewall-cmd --reload
对某个IP开放多个端口:
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.159.60.29" port protocol="tcp" port="1:65535" accept"
firewall-cmd --reload
如果有些命令不清楚,可以去下图所示网站搜索下Linux命令介绍。
首先你要知道你的linux系统的版本是属于哪个分发版的。当然如果你对自己的linux系统版本不知道的话也没关系。linux系统它的防火墙名为“iptables”如果你打开linux的话是黑色的话,那么你是处在终端阶段,这样如果需要打开你的防火墙的话,输入“chkconfig iptables on”,当然关闭防火墙的话只要将指令的“on”改成“off”,在执行命令即可。当然是需要重启计算机才能正式生效。 当然并不是只有一定命令启动和关闭linux系统防火墙。如果你不想让计算机重启在生效的话可以用“serv”命令。当我们需要开启防火墙的话输入“serv iptables start”,如需要关闭防火墙的话那就是将start替换成stop即可。当然执行serv命令的话如果电脑被重启,之后对防火墙的设置还是恢复到初始状态。所有对linux系统防火墙设置的信息参数全部会丢失。 以上只是介绍了关于linux防火墙的开启及关闭。如果要在防火墙上面设置某些端口的开关命令的话,可以通过找到修改编辑/etc/sysconfig/iptables文件。说到修改防火墙的参数的话所涉及到的知识点就很多了,你可以查看下Linux书籍《Linux就该这么学》了解详细的介绍。
一,安装并启动防火墙
[root@linux ~]# /etc/init.d/iptables start
当我们用iptables添加规则,保存后,这些规则以文件的形势存在磁盘上的,以CentOS为例,文件地址是/etc/sysconfig/iptables,我们可以通过命令的方式去添加,修改,删除规则,也可以直接修改/etc/sysconfig/iptables这个文件就行了。
1.加载模块
/in/modprobe ip_tables
2.查看规则
iptables -L -n -v
3.设置规则
#清除已经存在的规则
iptables -F
iptables -X
iptables -Z
#默认拒绝策略(尽量不要这样设置,虽然这样配置安全性高,但同时会拒绝包括lo环路在内的所#有网络接口,导致出现其他问题。建议只在外网接口上做相应的配置)
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
#ssh 规则
iptables -t filter -A INPUT -i 0 -p tcp –dport 22 -j ACCEPT
iptables -t filter -A OUTPUT -o 0 -p tcp –sport 22 -j ACCEPT
#本地还回及tcp握手处理
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
iptables -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
#www-dns 规则
iptables -I INPUT -p tcp –sport 53 -j ACCEPT
iptables -I INPUT -p udp –sport 53 -j ACCEPT
iptables -t filter -A INPUT -i 0 -p tcp –dport 80 -j ACCEPT
iptables -t filter -A OUTPUT -o 0 -p tcp –sport 80 -j ACCEPT
#ICMP 规则
iptables -A INPUT -p icmp –icmp-type echo-request-j ACCEPT
iptables -A INPUT -p icmp –icmp-type echo-reply -j ACCEPT
iptables -A OUTPUT -p icmp –icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp –icmp-type echo-reply -j ACCEPT
二,添加防火墙规则
1,添加filter表
1.[root@linux ~]# iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT //开放21端口
出口我都是开放的iptables -P OUTPUT ACCEPT,所以出口就没必要在去开放端口了。
2,添加nat表
1.[root@linux ~]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j MASQUERADE
将源地址是 192.168.10.0/24 的数据包进行地址伪装
3,-A默认是插入到尾部的,可以-I来插入到指定位置
1.[root@linux ~]# iptables -I INPUT 3 -p tcp -m tcp --dport 20 -j ACCEPT
2.[root@linux ~]# iptables -L -n --line-number
3.Chain INPUT (policy DROP)
4.num target prot opt source destination
5.1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
6.2 DROP icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 8
7.3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:20 //-I指定位置插的
8.4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
9.5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
10.6 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
11.7 DROP all -- 0.0.0.0/0 0.0.0.0/0 state INVALID,NEW
12.8 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 //-A默认插到
13.Chain FORWARD (policy ACCEPT)
14.num target prot opt source destination
15.Chain OUTPUT (policy ACCEPT)
16.num target prot opt source destination
三,查下iptable规则
1,查看filter表
1.[root@linux ~]# iptables -L -n --line-number |grep 21 //--line-number可以显示规则序号,在删除的时候比较方便
2.5 ACCEPT tcp -- 192.168.1.0/24 0.0.0.0/0 tcp dpt:21
如果不加-t的话,默认就是filter表,查看,添加,删除都是的
2,查看nat表
1.[root@linux ~]# iptables -t nat -vnL POSTROUTING --line-number
2.Chain POSTROUTING (policy ACCEPT 38 packets, 2297 bytes)
3.num pkts bytes target prot opt in out source destination
4.1 0 0 MASQUERADE all -- 192.168.10.0/24 0.0.0.0/0
四,修改规则
1.[root@linux ~]# iptables -R INPUT 3 -j DROP //将规则3改成DROP
五,删除iptables规则
1.[root@linux ~]# iptables -D INPUT 3 //删除input的第3条规则
2.[root@linux ~]# iptables -t nat -D POSTROUTING 1 //删除nat表中trouting的条规则
3.[root@linux ~]# iptables -F INPUT //清空 filter表INPUT所有规则
4.[root@linux ~]# iptables -F //清空所有规则
5.[root@linux ~]# iptables -t nat -F POSTROUTING //清空nat表POSTROUTING所有规则
六,设置默认规则
1.[root@linux ~]# iptables -P INPUT DROP //设置filter表INPUT默认规则是 DROP
所有添加,删除,修改后都要保存起来,/etc/init.d/iptables se.上面只是一些最基本的作,要想灵活运用,还要一定时间的实际作。
iptables配置常规映射及软路由
作用:虚拟化云平台网段192.168.1.0/24 通过一台linux(0:192.168.1.1、1:10.0.0.5)做软路由达到访问10.0.0.5能访问的网络范围,并且通过iptables的NAT映射提供服务。
NAT 映射网络端口:
效果: 10.0.0.5:2222 —-》 192.168.1.2:22
命令:iptable -t nat -A PREROUTING -D 10.0.0.5 -p tcp –dport 2222 -j DNAT –to-destination 192.168.1.2:22
serv iptables se
serv iptables restart
注意:1.在192.168.1.2的网络配置上需要将NAT主机的内网ip即192.168.1.1作为默认,如果10.0.0.5具有公网访问权限,dns则设置成公网对应dns
2. echo 1 》 /proc/sys/net/ip_forward 在NAT 主机上需要开启转发才能生效
软路由192.168.1.0/24通过10.0.0.5访问外网:
命令:iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT –to-source 10.0.0.5
serv iptables se
serv iptables restart
suse linux 防火墙设置方法一:
在terminal里输入serv iptables se就可以了
例:
[root@localhost init.d]# serv iptables se
Sing firewall rules to /etc/sysconfig/iptables: [ OK ]
[root@localhost init.d]#
这样就会自动生成/etc/sysconfig/iptable
suse linux 防火墙设置方法二:
1.入门作 Suse 进入命令窗口 ctrl alt + f1-f6 回到桌面 ctrl alt + f7(也可能是f8)
2.配置Suse静态IP地址 Suse的网络配置文件存放在:/etc/sysconfig/network目录下,其中的类似ifcfg--id-00:40:ca:c7:04:fc这样的文件是以太网卡的配...
suse linux 防火墙设置方法三:
关闭 iptables服务
用root用户权限执行 禁止iptables服务命令
chkconfig iptables off
方法2) 关闭SuSE Linux管理防火墙的服务
1. 检查 SuSE防火墙是否设置为启动
chkconfig --list | grep firewall
2. 关闭防火墙服务
chkconfig SuSEfirewall2_init off
chkconfig SuSEfirewall2_setup off
一、Linux下开启/关闭防火墙命令
1、性生效,重启后不会复原。
开启: chkconfig iptables on
关闭: chkconfig iptables off
2、 即时生效,重启后复原
开启: serv iptables start
关闭: serv iptables stop
需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭作。
在当开启了防火墙时,做如下设置,开启相关端口,
修改/etc/sysconfig/iptables 文件,添加以下内容:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
二、UBuntu关闭防火墙
iptables -A INPUT -i ! PPP0 -j ACCEPT
三、CentOS Linux 防火墙配置及关闭
执行”setup”命令启动文字模式配置实用程序,在”选择一种工具”中选择”防火墙配置”,然后选择”运行工具”按钮,出现防火墙配置界面,将”安全级别”设为”禁用”,然后选择”确定”即可.
或者用命令:
#/in/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
#/in/iptables -I INPUT -p tcp –dport 22 -j ACCEPT
#/etc/rc.d/init.d/iptables se
这样重启计算机后,防火墙默认已经开放了80和22端口
这里应该也可以不重启计算机:
#/etc/init.d/iptables restart
关闭防火墙服务即可:
查看防火墙信息:
#/etc/init.d/iptables status
关闭防火墙服务:
#/etc/init.d/iptables stop
版权声明:本文内容由互联。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发 836084111@qq.com 邮箱删除。