透明網關與透明防火牆

在honeyproject項目中的hoenywall裏面有一個透明的網關,後來我們叫做蜜網網關,然後這個網關上面配置了iptables防火牆,這樣我們也叫做透明防火牆。透明顧名思義是看不見,沒有存在感。所以,透明網關與透明防火牆是部署在網絡上的安全設備,而這兩種安全設備是其他網絡用戶不能感知其存在感的。網絡上的設備要做到透明的功能,可以使用網橋技術。linux系統上搭建網橋,把網橋配置成透明模式。網橋,作爲一種網絡橋樑,聯通網絡的兩端,支持兩端的網絡通訊。下面是配置透明網關、透明防火牆的過程。事實,一個有透明網橋功能的linux操作系統設備可以看做一個透明網關,然後,在該linux系統上做網絡流量監控工作,如:網路抓包、部署防火牆、入侵檢測等等。


1、安裝網橋

     1.1ubuntu安裝網橋命令:

        sudo apt-get install bridge-utils

     1.2centos安裝網橋命令:

        yum install bridge-utils

     1.3源碼安裝:

        去bridge-utils官網下載源碼安裝,安裝過程參照官網即可。


2、配置網橋

     2.1網橋的使用

        終端輸入命令:
        liang@liang-PC:~$ brctl -h
       
 打印網橋的使用幫助:
        Usage: brctl [commands]
commands:
	addbr     	<bridge>		add bridge
	delbr     	<bridge>		delete bridge
	addif     	<bridge> <device>	add interface to bridge
	delif     	<bridge> <device>	delete interface from bridge
	hairpin   	<bridge> <port> {on|off}	turn hairpin on/off
	setageing 	<bridge> <time>		set ageing time
	setbridgeprio	<bridge> <prio>		set bridge priority
	setfd     	<bridge> <time>		set bridge forward delay
	sethello  	<bridge> <time>		set hello time
	setmaxage 	<bridge> <time>		set max message age
	setpathcost	<bridge> <port> <cost>	set path cost
	setportprio	<bridge> <port> <prio>	set port priority
	show      	[ <bridge> ]		show a list of bridges
	showmacs  	<bridge>		show a list of mac addrs
	showstp   	<bridge>		show bridge stp info
	stp       	<bridge> {on|off}	turn stp on/off


     2.2創建網橋

        添加一個網橋:
        brctl addbr br0
        停止生成樹協議:
        brctl stp br0 off

     2.3添加網卡設備到網橋

        添加兩塊網卡到網橋:
        brctl addif br0 eth0
        brctl addif br0 eth1
        配置兩塊網卡不使用IP地址:
        ifconfig eth0 down
        ifconfig eth1 down
        ifconfig eth0 0.0.0.0 up
        ifconfig eth1 0.0.0.0 up
        因爲兩塊網卡作爲網橋的兩個接口,這兩個接口分別連接兩個不同的網絡,支持兩個網絡的正常通信,不再需要IP,只需要傳遞網絡流量即可。


3、配置透明網橋

     3.1透明網橋的ip設置

         網橋的IP設置:
         ifconfig br0 10.0.3.129 up (注意這樣的網橋並不是透明網橋,因爲使用的真實的IP地址,其他網絡設備可見)
         透明網橋的IP位置:
         ifconfig br0 0.0.0.0 up  (這樣網橋就沒有IP地址,其他設備就無法感知網橋的存在。到此,透明網橋基本配置完成,透明網關的屬性自然有了,但是透明防火牆的功能沒有完全支持,繼續往下。)


4、配置防火牆

     4.1防火牆的使用

        終端輸入命令:
        liang@liang-PC:~$ iptables -h

        打印iptabels防火牆的使用幫助:


iptables v1.4.21


Usage: iptables -[ACD] chain rule-specification [options]
       iptables -I chain [rulenum] rule-specification [options]
       iptables -R chain rulenum rule-specification [options]
       iptables -D chain rulenum [options]
       iptables -[LS] [chain [rulenum]] [options]
       iptables -[FZ] [chain] [options]
       iptables -[NX] chain
       iptables -E old-chain-name new-chain-name
       iptables -P chain target [options]
       iptables -h (print this help information)


Commands:
Either long or short options are allowed.
  --append  -A chain		Append to chain
  --check   -C chain		Check for the existence of a rule
  --delete  -D chain		Delete matching rule from chain
  --delete  -D chain rulenum
				Delete rule rulenum (1 = first) from chain
  --insert  -I chain [rulenum]
				Insert in chain as rulenum (default 1=first)
  --replace -R chain rulenum
				Replace rule rulenum (1 = first) in chain
  --list    -L [chain [rulenum]]
				List the rules in a chain or all chains
  --list-rules -S [chain [rulenum]]
				Print the rules in a chain or all chains
  --flush   -F [chain]		Delete all rules in  chain or all chains
  --zero    -Z [chain [rulenum]]
				Zero counters in chain or all chains
  --new     -N chain		Create a new user-defined chain
  --delete-chain
            -X [chain]		Delete a user-defined chain
  --policy  -P chain target
				Change policy on chain to target
  --rename-chain
            -E old-chain new-chain
				Change chain name, (moving any references)
Options:
    --ipv4	-4		Nothing (line is ignored by ip6tables-restore)
    --ipv6	-6		Error (line is ignored by iptables-restore)
[!] --protocol	-p proto	protocol: by number or name, eg. `tcp'
[!] --source	-s address[/mask][...]
				source specification
[!] --destination -d address[/mask][...]
				destination specification
[!] --in-interface -i input name[+]
				network interface name ([+] for wildcard)
 --jump	-j target
				target for rule (may load target extension)
  --goto      -g chain
                              jump to chain with no return
  --match	-m match
				extended match (may load extension)
  --numeric	-n		numeric output of addresses and ports
[!] --out-interface -o output name[+]
				network interface name ([+] for wildcard)
  --table	-t table	table to manipulate (default: `filter')
  --verbose	-v		verbose mode
  --wait	-w		wait for the xtables lock
  --line-numbers		print line numbers when listing
  --exact	-x		expand numbers (display exact values)
[!] --fragment	-f		match second or further fragments only
  --modprobe=<command>		try to insert modules using this command
  --set-counters PKTS BYTES	set the counter during insert/append
[!] --version	-V		print package version.


5、配置透明防火牆

     5.1配置透明防火牆

        配置網橋後發現經過網橋的流量並沒有受到iptables防火的控制,原因是系統沒有打開網橋支持防火牆的配置:
         echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
         同樣,bridge-nf-call-arptables、bridge-nf-call-ip6tables。到這裏,透明防火牆也配置完畢,此時經過網橋的流量就受到防火牆的控制。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章