歡迎您光臨本站 註冊首頁

linux下adsl拔號與共享上網

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0
linux下adsl拔號與共享上網
引自:http://blog.chinaunix.net/u/17549/showart.php?id=188498
多台電腦通過ADSL同時上網,如果有路由,那就太簡單了.
但是,如果沒路由只有交換機怎麼辦呢?一般有兩種方法.

1、用雙網卡(一個接內網,一個接外網)的機器裝代理伺服器軟體(windows下有winGet等)來完成,但這種方法要兩塊網卡(浪費),同時還要裝代理軟體(煩,而且還會被打盜版).
2、通過共享拔號連接來解決,這種方法很簡單且不需要其它的軟體.

對於windows下的第二種方法的實現網上有很文章且很簡單,在此不作闡述.

下面就我在linux(在centOS4.4,rhel as 4,fc5下測試通過)下如何通過adsl拔號與共享上網作一個簡單的記錄,希望對新手有所幫助.

1、拔號上網
1.1拔號軟體
linux下的拔號軟體很多,但比較好的是rp-pppoe,一般linux系統會自帶拔號軟體,如果你沒裝,請自己到google去找一個來裝上.
1.2拔號設置
切換為root用戶,只有root才能配置.
$ su
Password:
# /sbin/adsl-setup
按提示設置用戶名、密碼、DNS、及其它相關信息,下面是我的參考配置:
Welcome to the ADSL client setup. First, I will run some checks on
your system to make sure the PPPoE client is installed properly...

The following DSL config was found on your system:

Device: Name:
ppp0 DSLppp0

Please enter the device if you want to configure the present DSL config
(default ppp0) or enter 'n' if you want to create a new one:

LOGIN NAME

Enter your Login Name (default xyn0699647):

INTERFACE

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 ethX, where 'X' is a number.
(default eth0):

Do you want the link to come up on demand, or stay up continuously?
If you want it to come up on demand, enter the idle time in seconds
after which the link should be dropped. If you want the link to
stay up permanently, enter 'no' (two letters, lower-case.)
NOTE: Demand-activated links do not interact well with dynamic IP
addresses. You may have some problems with demand-activated links.
Enter the demand value (default no):

DNS

Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide dynamic DNS addresses',
enter 'server' (all lower-case) here.
If you just press enter, I will assume you know what you are
doing and not modify your DNS setup.
Enter the DNS information here:

PASSWORD

Please enter your Password:
Please re-enter your Password:

USERCTRL

Please enter 'yes' (two letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes):

FIREWALLING

Please choose the firewall rules to use. Note that these rules are
very basic. You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security. If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself. Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc. If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.

The firewall choices are:
0 - NONE: This script will not set any firewall rules. You are responsible
for ensuring the security of your machine. You are STRONGLY
recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation


2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
for a LAN
Choose a type of firewall (0-2):
Please enter a number from 0 to 2
The firewall choices are:
0 - NONE: This script will not set any firewall rules. You are responsible
for ensuring the security of your machine. You are STRONGLY
recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
for a LAN
Choose a type of firewall (0-2): 0

Start this connection at boot time

Do you want to start this connection at boot time?
Please enter no or yes (default no):

** Summary of what you entered **

Ethernet Interface: eth0
User name: xyn0699647
Activate-on-demand: No
DNS: Do not adjust
Firewalling: NONE
User Control: yes
Accept these settings and adjust configuration files (y/n)? y
Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0
Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets
(But first backing it up to /etc/ppp/chap-secrets.bak)
(But first backing it up to /etc/ppp/pap-secrets.bak)



Congratulations, it should be all set up!

Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'
to bring it down.
Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0'
to see the link status.


1.3拔號連接與斷開
輸入 '/sbin/ifup ppp0' 進行拔號連接戓'/sbin/ifdown ppp0'斷開拔號連接.
至此,如果一切正常,你就可以正常網上衝浪!
2、共享上網
通過上面的設置,你只能自己上網,要想其它電腦共享linux的連接上網,需要作如下的設置.

LINUX網路設置:
內網IP:192.168.0.1
子網掩碼:255.255.255.0


網關:192.168.0.1
DNS:根據各地的網路服務商不同,雲南昆明的是 202.98.160.68

註:要使設置生效,請先停止網卡,然後再激活.

其它的機器的設置只要保證與linux機器在一個網段並且網關設置為192.168.0.1就可以了,如:
192.168.0.2
255.255.255.0
192.168.0.1
DNS和主機一樣.

用你喜歡的編輯器(如vi,gedit等)打開LINUX主機的/etc/rc.d/rc.local
補上如下內容:
echo "1" > /proc/sys/net/ipv4/ip_forward
/sbin/ modprobe ip_nat_ftp
/sbin/ modprobe ip_conntrack
/sbin/ modprobe ip_conntrack_ftp
/sbin/ modprobe ip_conntrack_irc
/sbin/iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.0.1/24 -j MASQUERADE

運行一下rc.local
/etc/rc.d/rc.local
重新拔號,這樣linux下的共享連接就設置OK了!


[火星人 ] linux下adsl拔號與共享上網已經有443次圍觀

http://coctec.com/docs/linux/show-post-57390.html