精華區beta FreeBSD 關於我們 聯絡資訊
1.要先編譯kernel 首先先在 kernel 檔中加入下列內容 options IPFIREWALL options IPFIREWALL_DEFAULT_TO_ACCEPT options IPFIREWALL_VERBOSE options IPDIVERT options DUMMYNET 然後再去編譯 kernel 檔(編譯方法請參考實用設定教學中的編譯kernel教學) 2.編輯 /etc/rc.conf gateway_enable="YES" //設定本主機可做為gateway firewall_enable="YES" //這四行是防火牆的設定 firewall_type="simple" firewall_quiet="YES" tcp_extensions="YES" natd_interface="rl0" //定義natd所使用的網路卡,也就是使用真IP的網路 卡,中間的rl0是網路卡的 natd_enable="YES" 代號,請注意自己的設備再填上。 3.修改 /etc/rc.firewall 檔 先備份舊的rc.firewall cp rc.firewall re.firewallbak 再移除舊的 rm rc.firewall 再來建立 vi rc.firewall rc.firewall 內容如下 #!/bin/sh /sbin/ipfw -f flush //先清除所有的規則 =============== 設定 nat =============== # 這一行是允許 natd 可以在本機做任何存取動作通行 /sbin/ipfw add divert natd all from any to any via rl0 # 再把其他的通通放行 (注意!!必須放在最後一行) /sbin/ipfw add pass all from any to any =============== 封鎖ip設定 =============== #下面一行設定是指禁止IP為11.22.33.44的電腦連線到主機 # all ,是指 /etc/services 檔案中所記載的各項服務名稱。 /sbin/ipfw add deny all from 11.22.33.44 to any =============== 實用設定 =============== =============== 讓別人ping不到 =============== 加入下列這行 ipfw add 001 deny icmp from any to 主機的真實ip via rl0 防火牆規則,加上,編號第001號(最優先處理),拒絕icmp 封包(ping 用的封包), 從任何地方連到 主機的真實ip,將此規則使用於網路卡 rl0 這樣就可以了 =============== 限制使用者只能上某些網站 =============== 此設定是限制192.168.1.~254 整個網域,server ip 是設192.168.1.254 #!/bin/sh /sbin/ipfw -f flush /sbin/ipfw add pass all from 127.0.0.1 to 127.0.0.1 //設定server本機可以 跟server本機通訊 /sbin/ipfw add divert natd all from any to any via rl0 //設定nat可以任何通 行 /sbin/ipfw add pass all from 127.0.0.1 to any //讓本機可以通行到任 何地方 /sbin/ipfw add pass all from 192.168.1.255 to any //如果有設dhcp一定要 設這行 /sbin/ipfw add pass all from 192.168.1.1/24 to 192.168.1.254 //讓內部ip全部 可以連上本機 /sbin/ipfw add pass all from 192.168.1.1/24 to 168.95.1.1 //開放hinet dns 給使用者 #開放所有通行給該ip /sbin/ipfw add pass all from 192.168.1.1 to any /sbin/ipfw add pass all from 192.168.1.2 to any /sbin/ipfw add pass all from 192.168.1.3 to any #只開放kimo給其他使用者流覽(如果開放其他ip請自行發揮) /sbin/ipfw add pass all from 192.168.1.1/24 to 202.1.237.21 //www.kimo.com.tw的ip /sbin/ipfw add pass all from 192.168.1.1/24 to 202.1.237.22 //kimo的圖都在這 ip,也必須開放 /sbin/ipfw add deny all from 192.168.1.1/24 to any //把其他上面未允許的通 訊全部擋掉 /sbin/ipfw add pass all from any to any //剩下的通通放行 =============== IPFW限流 =============== /sbin/ipfw add pipe 1 ip from any to any out /sbin/ipfw add pipe 2 ip from any to any in /sbin/ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes /sbin/ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes =============== 將內部假ip透過nat對映到外部 =============== rc.conf 要先設定 ifconfig_rl0_alias0="inet 1.2.3.4 netmask 255.255.255.0" //在真ip網卡再另外 設定一個ip natd_flags="-config /etc/natd.conf" //指定nat 設定檔 在/etc下建立natd.conf內容如下 redirect_address 192.168.1.1 1.2.3.4 //如此就能把內部 192.168.1.1對映到1.2.3.4 http://www.gocar.idv.tw > -------------------------------------------------------------------------- < 發信人: [email protected] (或許…我不是我), 看板: FreeBSD 標 題: Re: 最近研究出來ㄉ 發信站: 元智資管螺絲起子 (Wed Jun 19 15:52:55 2002) 轉信站: Ptt!news.ntu!ctu-gate!ctu-peer!news.nctu!netnews.csie.nctu!news.csie.n ※ 引述《[email protected] (潛小開)》之銘言: > 1.要先編譯kernel > 首先先在 kernel 檔中加入下列內容 > options IPFIREWALL > options IPFIREWALL_DEFAULT_TO_ACCEPT conflict -> 1 > 2.編輯 /etc/rc.conf > gateway_enable="YES" //設定本主機可做為gateway > firewall_enable="YES" //這四行是防火牆的設定 > firewall_type="simple" conflict -> 2 > 3.修改 /etc/rc.firewall 檔 conflict -> 2 > =============== 設定 nat =============== > # 這一行是允許 natd 可以在本機做任何存取動作通行 > /sbin/ipfw add divert natd all from any to any via rl0 > # 再把其他的通通放行 (注意!!必須放在最後一行) > /sbin/ipfw add pass all from any to any conflict -> 1 > =============== IPFW限流 =============== > /sbin/ipfw add pipe 1 ip from any to any out > /sbin/ipfw add pipe 2 ip from any to any in > /sbin/ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes > /sbin/ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes ipfw rule inverted.