zoukankan      html  css  js  c++  java
  • 搭建防火墙服务

    搭建网络防火墙

        防火墙的IP充当网关,对两边主机相互发送的数据包进行检查

     1    两边的主机都必须要配置
     2    主机1配置路由:
     3      route add -net 192.168.145.0/24  gw 192.168.33.129
     4      route del -net 192.168.33.0/24
     5      inet 192.168.33.128
     6 
     7   路由主机的IP当成网关
     8      eth0   inet addr:192.168.33.130
     9      eth1   inet addr:192.168.145.130
    10 
    11   主机2配置路由:
    12      route add -net 192.168.33.0/24 gw 192.168.145.130
    13      inet 192.168.145.128
    14   跨网段ping主机:
    15     ping 192.168.33.128
    16     PING 192.168.33.128 (192.168.33.128) 56(84) bytes of data.
    17     64 bytes from 192.168.33.128: icmp_seq=1 ttl=63 time=0.920 ms
    18     64 bytes from 192.168.33.128: icmp_seq=2 ttl=63 time=2.41 ms
    19     64 bytes from 192.168.33.128: icmp_seq=3 ttl=63 time=2.26 ms
    20 
    21 [root@centos7 network-scripts]# ping 192.168.145.128
    22  PING 192.168.145.128 (192.168.145.128) 56(84) bytes of data.
    23  如果一直停住在这里表示对方接收到了数据包,但是没有路由返回.
    24 
    25  vi /etc/hosts
    26  192.168.33.128  www.a.com  www.b.com  www.c.com
    27  curl www.a.com
    28 
    29  在路由主机上配置路由规则
    30   2.iptables -I FORWARD -m string --algo bm --string "a.com" -j REJECT
    31 
    32   iptables -A FORWARD -j REJECT
    33   #拒绝所有的转发包
    34   iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    35   #允许转发外部主机的响应包
    36   iptables -I FORWARD 2 -s 192.168.145.0/24 -m state --state NEW -j ACCEPT
    37   #允许内部主机主动发起请求访问外部主机
    38   [root@yxh6 ~]# iptables -I FORWARD 2 -d 192.168.145.128 -p tcp --dport 22 -m state --state NEW -jACCEPT
    39   #允许外部主机访问内网的特定主机的特定服务
    View Code

    防火墙实现NAT(网络地址转换)

       SNAT

           修改了请求报文中的源IP     不修改端口        实现企业内网中的所有主机公用一个公网IP连接互联网

           iptables    -t   nat     -A    POSTROUTING    -s   10.0.1.0/24    -j   SNAT    -to-source 172.18.1.6
           iptables    -t    nat    -A    POSTROUTING    -s   10.0.1.0/24    -j   MASQUERADE

     DNAT

          修改了请求报文中的目标IP   不修改端口        实现公网中的主机通过内网网关IP访问到内部企业内网的主机

           iptables    -t   nat    -A    PREROUTING    -s    0/0    -d    172.18.100.6   -p    tcp    --dport  80   -j      DNAT    --todestination 10.0.1.22:8080 

       

    端口转发 

         iptables    -t    nat    -A      PREROUTING    -d     172.16.100.10    -p    tcp    --dport 80   -j    REDIRECT    --to-ports  8080

        

    管理防火墙中的表规则    

          查看防火墙指定表中的规则记录     默认管理的是filter表  如果要管理其它的表,需要添加 -t 选项

          [root@yxh6 ~]# iptables -nvL -t nat            列出nat表里面的所有记录
          [root@yxh6 ~]# iptables -F -t nat                删除nat表里面的所有记录

    firewalld服务 

         firewalld是CentOS 7.0新推出的管理netfilter的工具

         firewalld是配置和监控防火墙规则的系统守护进程.可以实现 iptables,ip6tables,ebtables的功能 

         firewalld服务由firewalld包提供 

         firewalld支持划分区域zone,每个zone可以设置独立的防火墙规则 

         网卡默认属于public zone,lo网络接口属于trusted  zone 

         firewalld配置 

            1.     firewall-config (firewall-config包)图形工具 

            2.      firewall-cmd (firewalld包)命令行工具 

        

  • 相关阅读:
    85. Maximal Rectangle
    120. Triangle
    72. Edit Distance
    39. Combination Sum
    44. Wildcard Matching
    138. Copy List with Random Pointer
    91. Decode Ways
    142. Linked List Cycle II
    异或的性质及应用
    64. Minimum Path Sum
  • 原文地址:https://www.cnblogs.com/yxh168/p/9248246.html
Copyright © 2011-2022 走看看