帮助中心

互联网上一些项目也越来越受欢迎,但是一般的项目都是要求真实的IP,所以要想获得大量的真实ip,一种动态VPS就诞生了,动态VPS采用PPTP或者ADSL拨号的方式获取动态IP,不仅可以做到获取区域性IP,还可以混拨,也就是可以获取全国各地的IP地址,这样对于网上业务来说就非常好了,轻松模拟出来各种地区IP,达到目的。博主最近接到一单,编写自动化拨号脚本,自动切换动态VPS的外网IP实现自动化,今天

当前位置: 首页  >> 新闻中心  >> 帮助中心  >> 查看详情

拨号VPS丨如何使用Linux系统的动态VPS自动更换IP?

浏览量:1152 时间:2023-08-16 05:34:05

互联网上一些项目也越来越受欢迎,但是一般的项目都是要求真实的IP,所以要想获得大量的真实ip,一种动态VPS就诞生了,动态VPS采用PPTP或者ADSL拨号的方式获取动态IP,不仅可以做到获取区域性IP,还可以混拨,也就是可以获取全国各地的IP地址,这样对于网上业务来说就非常好了,轻松模拟出来各种地区IP,达到目的。

博主最近接到一单,编写自动化拨号脚本,自动切换动态VPS的外网IP实现自动化,今天就记录下动态VPS的配置以及使用的姿势。

序列号 CPU RAM HDD 带宽 售价(美元) 免费试用
香港服务器1 E5-2620 32G 1T HDD 50M/无限流量 $196.00 立即申请
香港服务器2 E5-2650 32G 1T HDD 50M/无限流量 $256.00 立即申请
香港服务器3 E5-2680 32G 1T HDD 50M/无限流量 $316.00 立即申请
香港服务器4 E5-2690 32G 1T HDD 50M/无限流量 $336.00 立即申请
香港服务器5 E5-2697 32G 1T HDD 50M/无限流量 $376.00 立即申请
香港服务器6 E5-2620*2 32G 1T HDD 50M/无限流量 $376.00 立即申请
香港服务器7 E5-2650*2 32G 1T HDD 50M/无限流量 $436.00 立即申请
香港服务器8 E5-2680*2 32G 1T HDD 50M/无限流量 $476.00 立即申请
香港服务器9 E5-2690*2 32G 1T HDD 50M/无限流量 $556.00 立即申请
香港服务器10 E5-2697*2 32G 1T HDD 50M/无限流量 $596.00 立即申请
香港服务器11 E5-2680v4*2 32G 1T HDD 50M/无限流量 $696.00 立即申请
香港服务器12 E5-2698v4*2 32G 1T HDD 50M/无限流量 $796.00 立即申请

机器

先看下机器的配置,客户给过来的机器,配置如下:

系统:Linux

内存:512M

CPU:单核

硬盘:10G

带宽:2M

由于客户一次性给过来的机器比较多,100多台VPS,配置大体上都差不多,但是各个机器之间的差距很大,比如有的机器只有一个网卡,有的机器有好几张网卡,有的机器装的是Centos 6有的是Centos7,有的已经配置好拨号程序了,有的啥也没有等等各种情况都存在。

配置

既然是要实现自动化拨号程序,自然是要先判断下拨号程序在不在,Linux的拨号程序使用的是 pppoe-start 命令,注意,在不同的Linux里面拨号程序可能不一样,有的版本使用的是adsl-start命令,我这里首先查看下系统的发行版本,使用如下命令

[root@localhost~]#cat/etc/redhat-releaseCentOSLinuxrelease7.1.1503(Core)

看到返回了发行版本是centos 7.1,非常好,系统版本比较新,对脚本的支持也会更友好。

拨号命令pppoe-start在系统中已经自带了,所以这里咱们直接使用pppoe-setup设置我们的adsl拨号账号和密码,执行pppoe-setup命令后终端返回如下提示

WelcometothePPPoEclientsetup.First,IwillrunsomechecksonyoursystemtomakesurethePPPoEclientisinstalledproperly...LOGINNAMEEnteryourLoginName(defaultroot):

如果是第一次设置拨号会提示上面那种,如果之前有设置过,会提示是否覆盖之前的记录。

这里需要输入adsl账号,输入完之后回车,终端提示如下

INTERFACEEntertheEthernetinterfaceconnectedtothePPPoEmodemForSolaris,thisislikelytobesomethinglike/dev/hme0.ForLinux,itwillbeethX,where'X'isanumber.(defaulteth0):

询问pppoe拨号使用的网卡是哪个,当前这台机器只有一个网卡,所以选择默认的就行,后面再说多网卡的情况。

输入回车自动选择默认网卡后终端返回如下提示:

Doyouwantthelinktocomeupondemand,orstayupcontinuously?Ifyouwantittocomeupondemand,entertheidletimeinsecondsafterwhichthelinkshouldbedropped.Ifyouwantthelinktostayuppermanently,enter'no'(twoletters,lower-case.)NOTE:Demand-activatedlinksdonotinteractwellwithdynamicIPaddresses.Youmayhavesomeproblemswithdemand-activatedlinks.Enterthedemandvalue(defaultno):

这个提示意思是询问是按需链接还是始终保持连接,这个选项咱们在路由器的拨号设置里面经常看到,一般选择始终连接,这里系统默认选择始终连接,所以直接回车就好。

接着提示是否需要设置DNS

DNS:

PleaseentertheIPaddressofyourISP'sprimaryDNSserver.IfyourISPclaimsthat'theserverwillprovidedynamicDNSaddresses',enter'server'(alllower-case)here.Ifyoujustpressenter,IwillassumeyouknowwhatyouaredoingandnotmodifyyourDNSsetup.EntertheDNSinformationhere:

这里咱们就不需要设置DNS了,使用自动获取DNS即可,直接回车,之后提示输入adsl的密码

PASSWORD

Please enter your Password:

和再次输入密码

Please re-enter your Password:

然后会提示是否允许其他用户连接

USERCTRL

Please enter 'yes' (three letters, lower-case.) if you want to allow

normal user to start or stop DSL connection (default yes):

这里咱们不需要其他用户连接,所以输入no回车,接着提示防火墙设置

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' andset 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 whichallocate 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):

这里有三个选项,具体含义不多说,这里咱们不需要设置防火墙,输入0回车。

系统询问是否需要开机启动自动连接

Start this connection at boot time

Do you want to start this connection at boot time?

Please enter no or yes (default no):

输入yes回车设置成开机自动连接,最后系统展示刚刚的设置以及询问是否生成配置文件

** Summary of what you entered **

Ethernet Interface: eth0

User name: adsluser

Activate-on-demand: No

DNS: Do not adjust

Firewalling: NONE

User Control: no

Accept these settings and adjust configuration files (y/n)?

输入y后回车整个adsl拨号就设置完成了,系统会给出一个提示

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/pppoe-status /etc/sysconfig/network-scripts/ifcfg-ppp0'to see the link status.

提示中写明了配置文件的位置以及基本的使用方法。

在整个拨号过程中咱们能用到的命令差不多只有三个,pppoe-start、pppoe-stop、pppoe-status,pppoe-status命令是查询adsl拨号的状态,自动化脚本需要通过这个命令查询是否拨号成功。

配置完成之后咱们就来测试下拨号是否成功,直接执行pppoe-start命令,稍等几秒钟,如果没有报错继续执行pppoe-status命令查询下是否拨号成功。

我这里系统返回如下

pppoe-status: Link is up and running on interface ppp0

3: ppp0: mtu 1480 qdisc pfifo_fast state UNKNOWN qlen 3

link/ppp

24小时服务器机房客服
帮助中心
  • 24H在线
  • Tg纸飞机