linux pppoe 拨号日志,PPPoe宽带拨号

0. 确认本机 linux 发行版以及系统版本1cat /pro/version

如输出1Linux version 3.10.0-862.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Fri Apr 20 16:44:24 UTC 2018

可看到是 Red Hat 4.8.5-28,确认是红帽系统后,我们才能用以下方法拨号上网

1. 检查自己的机器是否安装了rp-pppoe1rpm -qa rp-pppoe

如出现类似以下信息,rp-pppoe-3.11-7.el7.x86_64则证明已经预安装了。否则需要自行安装1pm -ivh rp-pppoe-3.8-5.fc10.i386.rpm

接下来开始拨号上网

2. 设置拨号参数 – pppoe-setup

终端执行以下命令后,会出现一系列需要配置的内容

注意:配置拨号只需要在最开始配置一次即可1pppoe-setup

a. 配置 DSL – 回车默认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:

如果要配置当前的DSL配置,请输入设备

(默认为ppp0),如果要创建一个新的,请输入’n’:

默认则可

b. LOGIN NAME – 输入宽带账号Enter your Login Name (default root): 200000123456

即输入当前的宽带帐号

c. INTERFACE – 输入连接的以太网接口名称 – 默认是 eth0,回车即可Enter the Ethernet interface connected to the PPPoE modem

For Solaris, this is likely to be something like /dev/hme0.

For Linux, it will be ethX, where ‘X’ is a number.

输入连接到PPPoE调制解调器的以太网接口

对于Solaris,这可能类似于/ dev / hme0。

对于Linux,它将是ethX,其中“ X”是数字。

(默认eth0):

d.是否自动切断网络连接 – 默认是no,回车即可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):

现在系统要求询问你是否希望在没有联网的情况下,系统是否在空闲一段时间后,自动切断同网络的连接。我不喜欢这样,我希望在不用的时候,自己手动断掉连接。于是选择默认值,直接输入回车。

e.DNS – 设置DNS参数 – 输入 serverPlease 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:

配置DNS,此处输入server来自动获取DNS

f. PASSWORD – 输入宽带账号密码Please enter your Password:123456Please re-enter your Password:123456

g. USERCTRL – 是否允许普通用户开启或关闭PPPoE拨号,默认是允许,回车即可Please enter ‘yes’ (three letters, lower-case.) if you want to allow

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

h. FIREWALLING – 防火墙选择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 workstation2 – MASQUERADE: Appropriate for a machine acting as an Internet gateway

for a LAN

0 为不开启任何防火墙策略,1 为适用于基本的独立网络冲浪工作站

,2适用于充当局域网Internet网关的机器。自己选择一个,然后输入对应的数字即可

i. 开机启动配置,此处输入yes开机自动启动PPPoE拨号Do you want to start this connection at boot time?Please enter no or yes (default no):yes

j. 配置确认,没配错的话输入 y 保存配置1

2

3

4

5

6

7Ethernet Interface: eth0

User name: 02519885455

Activate-on-demand: No

DNS addresses: Supplied by ISP's server

Firewalling: NONE

User Control: yes

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

配置默认保存在 /etc/sysconfig/network-scripts/ifcfg-ppp0

PPPoe 拨号日志在 /var/log/messages 中,可以通过 tail -f /var/log/messages 查看 PPPoe 最新拨号日志内容

3. 拨号上网1

2

3

4

5

6

7

8# 拨号

pppoe-start

# 停止拨号

pppoe-stop

# 动态换IP

pppoe-stop && pppoe-start

# 拨号连接状态

pppoe-status

4. 脚本自动拨号

大概思路是,通过 ssh 登录上服务器,然后执行拨号命令,再返回当前的 ip

这里远程登陆服务器用的是 paramiko 这个库,比较好用还有 pexpect1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48# -*- coding: utf-8 -*-

# @Time : 2020/12/23 下午7:09

# @Author : wu

"""

pip install paramiko

"""

import paramiko

import time

import fire

def ssh_connect(host, port, user, passwd, **kwargs):

"""

获取 ssh 客户端

"""

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect(host, port, user, passwd, **kwargs)

return ssh

def get_ip(ssh: paramiko.SSHClient) -> str:

"""

改变 ip 并返回 ip

"""

ssh.exec_command("pppoe-stop && pppoe-start")

ip = ''

while not ip:

# 拨完号有可能暂时没那么快获取到 ip

time.sleep(0.5)

stdin, stdout, stderr = ssh.exec_command("ifconfig ppp0 | grep inet | awk '{print $2}'")

ip = stdout.read().decode('utf-8').strip()

print('未获取到 ip')

# 如果是搭配 squid 使用,可能每次拨完号后都要重新开放指定端口

ssh.exec_command("iptables -I INPUT -p tcp –dport 3128 -j ACCEPT")

return ip

def run():

ssh = ssh_connect('nanjingdx3.f3322.net', 20094, 'root', 'pawdd')

ip = get_ip(ssh)

print(ip)

ssh.close()

if __name__ == '__main__':

fire.Fire(run)

在此仅仅是提供了个思路,具体更高级的用法还可以看 paramiko

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注