# Disallow setup of all other TCP connections$fwcmd add deny tcp from any to any setup此后屏蔽所有其他種類的TCP連接請(qǐng)求數(shù)據(jù)包,因此如果要打開其他TCP連接請(qǐng)求,就需要在這個(gè)規(guī)則之前進(jìn)行定義 。
# Allow DNS queries out in the world$fwcmd add pass udp from any 53 to ${ip}$fwcmd add pass udp from ${ip} to any 53# Allow NTP queries out in the world$fwcmd add pass udp from any 123 to ${ip}$fwcmd add pass udp from ${ip} to any 123# Everything else is denied as default.此后定義對(duì)UDP數(shù)據(jù)包的過濾規(guī)則,只許可DNS和NTP協(xié)議通過,而屏蔽其他UDP數(shù)據(jù)包 。
上面這些指令都是client類型的過濾規(guī)則,綜合上面的指令,這就表示為屏蔽外部計(jì)算機(jī)向本地除smtp之外的TCP連接請(qǐng)求,而允許本地計(jì)算機(jī)向外發(fā)起連接請(qǐng)求,屏蔽除DNS和NTP之外的其他UDP數(shù)據(jù)包 。這些過濾規(guī)則可以有效的保護(hù)一個(gè)不對(duì)外提供服務(wù)的客戶系統(tǒng) 。但是,如果要對(duì)外提供網(wǎng)絡(luò)服務(wù),就需要更改這里的設(shè)置,打開需要提供服務(wù)的端口,例如打開TCP端口22,以使得ssh客戶能連接到系統(tǒng)中 。
elif [ "${firewall_type}" = "simple" ]; then############# This is a prototype setup for a simple firewall.Configure this machine# as a named server and ntp server, and point all the machines on the inside# at this machine for those services.############# set these to your outside interface network and netmask and ipoif="ed0"onet="192.168.4.0"omask="255.255.255.0"oip="192.168.4.17"# set these to your inside interface network and netmask and ipiif="ed1"inet="192.168.3.0"imask="255.255.255.0"iip="192.168.3.17"防火墻類型simple用于設(shè)置一個(gè)簡(jiǎn)單的防火墻系統(tǒng),用于保護(hù)內(nèi)部網(wǎng)絡(luò)中的計(jì)算機(jī) 。由于防火墻系統(tǒng)需要連接多個(gè)網(wǎng)絡(luò)界面,一個(gè)用于連接外部網(wǎng)絡(luò),而其他用于連接內(nèi)部網(wǎng)絡(luò) 。這個(gè)簡(jiǎn)單的防火墻只針對(duì)兩個(gè)網(wǎng)絡(luò)界面進(jìn)行了過濾規(guī)則的設(shè)置,內(nèi)部網(wǎng)絡(luò)的界面iif,外部網(wǎng)絡(luò)的界面oif,因此它只適合只有兩個(gè)網(wǎng)絡(luò)界面的防火墻系統(tǒng) 。
當(dāng)真正要使用這個(gè)防火墻設(shè)置的時(shí)候,首先就要修改iif與oif的IP地址,網(wǎng)絡(luò)掩碼等相關(guān)設(shè)置,與本地系統(tǒng)實(shí)際使用的設(shè)置相同 。
# Stop spoofing$fwcmd add deny all from ${inet}:${imask} to any in via ${oif}$fwcmd add deny all from ${onet}:${omask} to any in via ${iif}這兩個(gè)過濾規(guī)則用于丟棄涉及IP地址欺騙的數(shù)據(jù)包,這包括來自于外部網(wǎng)絡(luò)界面,但源地址為內(nèi)部網(wǎng)絡(luò)地址,或者來自于內(nèi)部網(wǎng)絡(luò)界面,但源地址為外部網(wǎng)絡(luò)地址的數(shù)據(jù)包 。由于這些數(shù)據(jù)包涉及IP地址欺騙,每個(gè)路由器都應(yīng)該丟棄這樣的數(shù)據(jù)包 。
# Stop RFC1918 nets on the outside interface$fwcmd add deny all from 192.168.0.0:255.255.0.0 to any via ${oif}#$fwcmd add deny all from any to 192.168.0.0:255.255.0.0 via ${oif}$fwcmd add deny all from 172.16.0.0:255.240.0.0 to any via ${oif}$fwcmd add deny all from any to 172.16.0.0:255.240.0.0 via ${oif}$fwcmd add deny all from 10.0.0.0:255.0.0.0 to any via ${oif}$fwcmd add deny all from any to 10.0.0.0:255.0.0.0 via ${oif}RFC1918中定義了一些只用于內(nèi)部網(wǎng)絡(luò)的IP地址,這些地址不能用于Internet上的計(jì)算機(jī),而只能用于內(nèi)部網(wǎng)絡(luò)中 。這里禁止從外部網(wǎng)絡(luò)界面上向內(nèi)部地址進(jìn)行數(shù)據(jù)傳輸,以防止外部網(wǎng)絡(luò)向內(nèi)部網(wǎng)絡(luò)的地址進(jìn)行連接,也是防火墻的重要功能之一 。
注意,上例中與系統(tǒng)提供的缺省設(shè)置是不同的,將其中對(duì)應(yīng)于實(shí)際使用的內(nèi)部地址的一行加上了注釋 。這是因?yàn)樵撛O(shè)置與natd相互沖突,使得natd發(fā)送的數(shù)據(jù)(具備內(nèi)部網(wǎng)絡(luò)地址)也被過濾 ??梢院?jiǎn)單的注釋對(duì)應(yīng)本地網(wǎng)絡(luò)地址的設(shè)置項(xiàng),以使得它們能夠相互協(xié)議,而將保護(hù)功能留給natd來完成 。如果不使用natd,就不必使用上面的注釋 。
# Allow TCP through if setup succeeded$fwcmd add pass tcp from any to any established# Allow setup of incoming email$fwcmd add pass tcp from any to ${oip} 25 setup# Allow access to our DNS$fwcmd add pass tcp from any to ${oip} 53 setup# Allow access to our WWW$fwcmd add pass tcp from any to ${oip} 80 setup# Reject&Log all setup of incoming connections from the outside$fwcmd add deny log tcp from any to any in via ${oif} setup# Allow setup of any other TCP connection$fwcmd add pass tcp from any to any setup此后屏蔽除了email,www,dns之外的其他向內(nèi)部網(wǎng)絡(luò)的TCP連接請(qǐng)求,而只允許向外進(jìn)行連接 。當(dāng)實(shí)際內(nèi)部網(wǎng)絡(luò)要向外提供服務(wù)時(shí),再添加連接許可 。
推薦閱讀
- 66 FreeBSD連載:安裝samba
- FreeBSD Lastcomm介紹
- 一加7pro設(shè)置游戲模式的簡(jiǎn)單操作教程
- 掌緣漫畫設(shè)置密碼操作過程
- FreeBSD 常用名詞概述
- 一加7pro中設(shè)置翻轉(zhuǎn)靜音的操作步驟
- 兩臺(tái)路由器連接方法
- 63 FreeBSD連載:集成Unix和Windows的方式
- Reno Ace中設(shè)置自由收藏的簡(jiǎn)單操作教程
- 紅米note7設(shè)置sos緊急求助操作過程
