国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Unix > 正文

用 IPFW 為 FreeBSD 操作系統(tǒng)建立防火墻

2019-09-08 23:19:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Ipfirewall(即IPFW)是一個(gè)FreeBSD操作系統(tǒng)下的IP數(shù)據(jù)包過(guò)濾和通信記錄工具。IPFW作為一個(gè)獨(dú)立的運(yùn)行時(shí)刻可裝載模塊,就包含在基本的FreeBSD安裝包中。在rc.conf中含有語(yǔ)句“firewall_enable=YES”時(shí),系統(tǒng)會(huì)動(dòng)態(tài)地裝載內(nèi)核模塊。

第一步:為IPFW而編譯FreeBSD內(nèi)核

這一步是可選的。如果你不想啟用NAT功能,你就沒(méi)有必要將IPFW編譯到FreeBSD內(nèi)核中。然而一些老的版本可能沒(méi)有編譯IPFW。下面我們介紹將IPFW編譯進(jìn)入內(nèi)核中去的方法。

如果你得到如下的一個(gè)錯(cuò)誤消息:“ipfw: getsockopt(IP_FW_GET): Protocol not available ”,即協(xié)議不可使用,那你就必須編譯內(nèi)核的源代碼。

另一個(gè)可選項(xiàng)是打開(kāi)默認(rèn)的內(nèi)核配置文件/usr/src/sys/i386/conf,并找到IPFIREWALL選項(xiàng):

 

# grep IPFIREWALL /usr/src/sys/i386/conf

第二步:編譯并安裝帶有IPFW的定制內(nèi)核

首先是復(fù)制默認(rèn)的內(nèi)核文件:

 

# cd /usr/src/sys/i386/conf# cp GENERIC IPFWKERNEL

然后增加IPFW支持:

 

# vi IPFWKERNEL

添加下面的指令:

 

options IPFIREWALL # required for IPFWoptions IPFIREWALL_VERBOSE # optional; loggingoptions IPFIREWALL_VERBOSE_LIMIT=10 # optional; don't get too many log entriesoptions IPDIVERT # needed for natd


保存并關(guān)閉文件。編譯內(nèi)核,鍵入如下的命令:

 

# cd /usr/src# make buildkernel KERNCONF=IPFWKERNEL

安裝新的內(nèi)核:

 

# make installkernel KERNCONF=IPFWKERNEL

現(xiàn)在重新啟動(dòng)系統(tǒng):

 

# reboot

第三步:?jiǎn)⒂肐PFW

首先打開(kāi)/etc/rc.conf文件:

 

# vi /etc/rc.conf

然后,添加如下的設(shè)置:

 

firewall_enable="YES"firewall_script="YES"firewall_script="/usr/local/etc/ipfw.rules"


保存并關(guān)閉文件。

第四步:編寫(xiě)防火墻規(guī)則腳本

你需要將防火墻規(guī)則放到一個(gè)被稱(chēng)為/usr/local/etc/ipfw.rule的腳本中:

 

# vi /usr/local/etc/ipfw.rule

添加如下的代碼:

 

IPF="ipfw -q add"ipfw -q -f flush#loopback$IPF 10 allow all from any to any via lo0$IPF 20 deny all from any to 127.0.0.0/8$IPF 30 deny all from 127.0.0.0/8 to any$IPF 40 deny tcp from any to any frag# statefull$IPF 50 check-state$IPF 60 allow tcp from any to any established$IPF 70 allow all from any to any out keep-state$IPF 80 allow icmp from any to any# open port ftp (21,22), ssh (22), mail (25)# http (80), dns (53) etc$IPF 110 allow tcp from any to any 21 in$IPF 120 allow tcp from any to any 21 out$IPF 130 allow tcp from any to any 22 in$IPF 140 allow tcp from any to any 22 out$IPF 150 allow tcp from any to any 25 in$IPF 160 allow tcp from any to any 25 out$IPF 170 allow udp from any to any 53 in$IPF 175 allow tcp from any to any 53 in$IPF 180 allow udp from any to any 53 out$IPF 185 allow tcp from any to any 53 out$IPF 200 allow tcp from any to any 80 in$IPF 210 allow tcp from any to any 80 out# deny and log everything$IPF 500 deny log all from any to any


保存并關(guān)閉文件。

第五步:?jiǎn)?dòng)防火墻

你可以重新啟動(dòng)服務(wù)器,或者通過(guò)在命令行輸入如下的命令,可以重新加載這些規(guī)則:

 

# sh /usr/local/etc/ipfw.rules

如果要依次列示所有的規(guī)則,需要鍵入下面的命令:

 

# ipfw list
 
 

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 库尔勒市| 工布江达县| 泽普县| 石河子市| 集安市| 延长县| 栾川县| 湖北省| 红桥区| 即墨市| 台东市| 永昌县| 陵水| 盘山县| 孙吴县| 乐清市| 蕲春县| 淮南市| 新平| 营山县| 满洲里市| 德钦县| 南汇区| 峨眉山市| 方城县| 灌阳县| 贵州省| 从化市| 镇远县| 凤庆县| 卢龙县| 天峻县| 吴忠市| 吉首市| 遵义县| 曲周县| 永顺县| 思南县| 麻栗坡县| 清镇市| 高要市|