ADSL利用NAT實(shí)現(xiàn)上網(wǎng)應(yīng)用于Linux服務(wù)器
如果你安裝了Linux系統(tǒng),怎樣才能實(shí)現(xiàn)Linux上網(wǎng)呢?這里為你講解Linux服務(wù)器ADSL利用NAT實(shí)現(xiàn)上網(wǎng)共享,讓你輕松應(yīng)用Linux服務(wù)器上網(wǎng)。希望你能學(xué)會(huì)Linux服務(wù)器ADSL利用NAT實(shí)現(xiàn)上網(wǎng)。
1、 網(wǎng)卡配置。
兩塊網(wǎng)卡,eth0為撥號(hào)網(wǎng)卡,IP:192.168.1.1(其他的地址也可);eth1為內(nèi)網(wǎng)網(wǎng)卡,IP:192.168.0.1.掩碼均為255.255.255.0.局域網(wǎng)網(wǎng)段為192.168.0.0.
注意:此處兩塊網(wǎng)卡均不能設(shè)網(wǎng)關(guān)。 撥號(hào)(PPPOE)的網(wǎng)卡不用設(shè)置
2、 PPPoE軟件的升級(jí)與安裝
1) 在 http://www.roaringpenguin.com/pppoe/#download 下載
2) 安裝rp-pppoe.以root身份執(zhí)行
rpm –Uvh rp-pppoe-3.5-1.i386.rpm
3、 修改/etc/ sysctl.conf
將其中的
net.ipv4.ip_forward = 0
改為
net.ipv4.ip_forward = 1
4、 去除ipchains模塊,只選擇iptables方法如下:
1)setup
2)選擇system service
3)去除ipchains
4)選中iptables
5)重啟機(jī)器
5、 PPPoE客戶端配置
在rp-pppoe-3.5-1.i386.rpm安裝完畢后,接下來就可進(jìn)行PPPoE客戶端配置了。過程如下。
#/usr/sbin/adsl-setup
>;>;>; Enter your PPPoE user name: ——此處輸入撥號(hào)帳號(hào)的用戶名
>;>;>; Enter the Ethernet interface connected to the ADSL modem For Solaris, this is likely to be something like /dev/hme0. For Linux, it will be ethn, where n is a number. (default eth0): ——輸eth0
>;>;>; Enter the demand value (default no): ——輸no
>;>;>; Enter the DNS information here: ——輸210.52.149.2(視當(dāng)?shù)剡\(yùn)營商的DNS服務(wù)器IP而定)
>;>;>; Please enter your PPPoE password: ——輸網(wǎng)通用戶口令
>;>;>; Choose a type of firewall (0-2): ——輸0
>;>;>; Accept these settings and adjust configuration files (y/n)? ——輸y
6、 啟動(dòng)撥號(hào)連接
/usr/sbin/adsl-start
成功連接后,屏幕顯示Connected.
此時(shí)這臺(tái)linux已可以上網(wǎng)瀏覽了。
7、 IP偽裝
為了使局域網(wǎng)中的其他機(jī)器能通過Linux服務(wù)器共享上網(wǎng),至少須執(zhí)行下面的命令:
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
完成后,在192.168.0.0網(wǎng)段(網(wǎng)關(guān)為192.168.0.1)的PC機(jī)就可透過Linux上網(wǎng)了!
8、 開機(jī)自啟動(dòng)
為了使Linux服務(wù)器能夠自動(dòng)撥號(hào),執(zhí)行下面步驟。
1)chkconfig ——add adsl
2)setup
3)選擇system services
4)選中ADSL
5)OK退出
6)打開/etc/rc.d/rc.local,在該文件的末尾添上下面語句
- echo "[OK]"
- echo "Drop ICMP form anywhere"
- echo 1 >; /proc/sys/net/ipv4/icmp_echo_ignore_all
- echo "[OK]"
- iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
說明:前面四句用于關(guān)閉ICMP,防止別人Ping.
9、至此,一切OK,一個(gè)簡單的撥號(hào)建成了。重啟機(jī)器后,發(fā)現(xiàn)linux的internet共享連接已經(jīng)一切就緒了。這樣就可以Linux服務(wù)器實(shí)現(xiàn)上網(wǎng)了。
【編輯推薦】