ADSL利用NAT實現上網應用於Linux伺服器

來源:互聯網
上載者:User

如果你安裝了Linux系統,怎樣才能實現Linux上網呢?這裡為你講解Linux伺服器ADSL利用NAT實現上網共用,讓你輕鬆應用Linux伺服器上網。希望你能學會Linux伺服器ADSL利用NAT實現上網。

1、 網卡配置。

兩塊網卡,eth0為撥號網卡,IP:192.168.1.1其他的地址也可);eth1為內網網卡,IP:192.168.0.1.掩碼均為255.255.255.0.區域網路網段為192.168.0.0.

注意:此處兩塊網卡均不能設網關。 撥號PPPOE)的網卡不用設定

2、 PPPoE軟體的升級與安裝

1) 在 http://www.roaringpenguin.com/pppoe/#download 下載

2) 安裝rp-pppoe.以root身份執行

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)重啟機器

5、 PPPoE用戶端配置

在rp-pppoe-3.5-1.i386.rpm安裝完畢後,接下來就可進行PPPoE用戶端配置了。過程如下。

#/usr/sbin/adsl-setup

>;>;>; Enter your PPPoE user name: ——此處輸入撥號帳號的使用者名稱
>;>;>; 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視當地電訊廠商的DNS伺服器IP而定)
>;>;>; Please enter your PPPoE password: ——輸網通使用者口令
>;>;>; Choose a type of firewall (0-2): ——輸0
>;>;>; Accept these settings and adjust configuration files (y/n)? ——輸y

6、 啟動撥號連線

/usr/sbin/adsl-start

成功串連後,螢幕顯示Connected.

此時這台linux已可以上網瀏覽了。

7、 IP偽裝

為了使區域網路中的其他機器能通過Linux伺服器共用上網,至少須執行下面的命令:

iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

完成後,在192.168.0.0網段網關為192.168.0.1)的PC機就可透過Linux上網了!

8、 開機自啟動

為了使Linux伺服器能夠自動撥號,執行下面步驟。

1)chkconfig ——add adsl

2)setup

3)選擇system services

4)選中ADSL

5)OK退出

6)開啟/etc/rc.d/rc.local,在該檔案的末尾添上下面語句

  1. echo "[OK]"  
  2. echo "Drop ICMP form anywhere"  
  3. echo 1 >; /proc/sys/net/ipv4/icmp_echo_ignore_all  
  4. echo "[OK]"  
  5. iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE 

說明:前面四句用於關閉ICMP,防止別人Ping.

9、至此,一切OK,一個簡單的撥號建成了。重啟機器後,發現linux的internet共用串連已經一切就緒了。這樣就可以Linux伺服器實現上網了。

  1. 全面解析Linux叢集技術的要點
  2. LifeKeeper又一款Linux伺服器叢集軟體
  3. 講解Linux伺服器叢集技術
  4. 詳解保護Linux伺服器七步驟
  5. 全面介紹Linux配置ntop

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.