很多人反覆在問linux如何設定才能實現共享上網,乾脆寫乙個步驟出來吧
1、vi /usr/local/sbin/firewall
**:
#! /bin/bash
# project by platinum, 2005-05-12"
# set inte***ce wan
wan_ip="外網絡卡位址"
wan_eth="eth0"
wan_mask="外網絡卡掩碼位址"
# set inte***ce lan
lan_ip="內網絡卡位址"
lan_eth="eth1"
lan_mask="內網絡卡掩碼位址"
# set mode (lan or adsl)
mode="lan"
# set default gateway
gateway="閘道器位址"
# set manager
manager_ip="內網管理員ip"
manager_mac="xx:xx:xx:xx:xx:xx"
# initialize modules
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
echo 1 > /proc/sys/***/ipv4/ip_forward
# initialize inte***ce lan
ifconfig $lan_eth $lan_ip ***mask $lan_mask
# initialize policy
iptables -p input drop
iptables -p forward accept
iptables -f
iptables -t nat -f
# deny ack attack
iptables -a input -p tcp ! --syn -m state --state new -j drop
iptables -a forward -p tcp ! --syn -m state --state new -j drop
# initialize rules
iptables -a input -i lo -j accept
iptables -a input -i $lan_eth -s $mange_ip -m mac --mac-source $mange_mac -m state --state new,related,established -j accept
iptables -a input -m state --state related,established -j accept
case "$mode" in
lan)
# initialize inte***ce wan
ifconfig $wan_eth $wan_ip ***mask $wan_mask
iptables -t nat -a postrouting -s $lan_*** -o $wan_eth -j snat --to $wan_ip
;; adsl)
iptables -t nat -a postrouting -s $lan_*** -o ppp0 -j masquerade
gateway=`ifconfig ppp0|grep i***|awk ''|awk -f: ''`
;; esac
ip route replace default via $gateway
2、chmod 700 /usr/local/sbin/firewall
只有root許可權才能讀寫執行
3、echo "/usr/local/sbin/firewall" >> /etc/rc.local
讓系統啟動後自動執行指令碼
4、reboot
重啟系統
自己根據自己的情況改一下就可以了,應該不難懂
注意:
如果是直接設定ip上網,mode選擇lan
如果是用pppoe撥號上網,mode選擇adsl,且保證在執行這個指令碼之前已經撥號
乙個shell防火牆的小指令碼
指令碼如下 bin sh ver 1.1 date 2009.7.14 iptables sbin iptables int net 192.168.1.0 24 mdprobe sbin modprobe ifconfig eth0 192.168.1.4 netmask 255.255.255....
每天乙個Linux命令 22 關閉防火牆
防火牆分為selinux,iptables 1 iptables service iptables status可以檢視到iptables服務的當前狀態。但是即使服務執行了,防火牆也不一定起作用,你還得看防火牆規則的設定 iptables l 在此說一下關於啟動和關閉防火牆的命令 重啟後生效 開啟 ...
寫乙個高效且通用的拷貝函式
通用的拷貝函式呢,對於大部分內建型別來說,都是可以直接拷貝的,我們呼叫memcpy 就可以直接完成,並且效率也很高。但是出現類似於string類時,直接用mempy 就會出現淺拷貝的問題。這時,我們就需要對各種型別進行選擇,選擇合適的拷貝方式。思路 首先,我們會考慮下多傳乙個引數進行判斷一下,這樣很...