wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用,可以修改配置
sed -i -e ‘/mirrors.cloud.aliyuncs.com/d’ -e ‘/mirrors.aliyuncs.com/d’ /etc/yum.repos.d/CentOS-Base.repo
yum makecache
yum repolist
yum -y install epel-release
yum install vconfig -y
modprobe 8021q
lsmod | grep 8021q
ip addr
vconfig add ens192 101
vconfig add ens192 102
cat /proc/net/vlan/config
cd /etc/sysconfig/network-scripts/
vi ifcfg-ens192.101
TYPE=vlan
PHYSDEV=ens192
VLAN=yes
VLAN_ID=101
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
NAME=ens192.101
DEVICE=ens192.101
ONBOOT=yes
cp ifcfg-ens192.101 ifcfg-ens192.102
vi ifcfg-ens192.102
DEVICE=ens192.102
BOOTPROTO=none
ONBOOT=yes
VLAN=yes
systemctl restart network
ip addr
yum install rp-pppoe -y
pppoe-setup
Welcome to the PPPoE client setup. First, I will run some checks on
your system to make sure the PPPoE client is installed properly…
LOGIN NAME
Enter your Login Name (default root): 1
INTERFACE
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.
(default eth0): ens192.101
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): 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’ (three letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes): 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): 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: ens192.101
User name: 1
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)
cat /etc/sysconfig/network-scripts/ifcfg-ppp0
cat /etc/ppp/chap-secrets
tail -f /var/log/messages 查看 PPPoe 最新拨号日志内容
配置多线路:
方法一:
(1)直接拷贝
cp /etc/sysconfig/network-scripts/ifcfg-ppp0 /etc/sysconfig/network-scripts/ifcfg-ppp1
(2)修改其中的ppp0为ppp1,
修改PIDFILE=/var/run/pppoe-adsl.pid 为PIDFILE=/var/run/pppoe-adsl1.pid
修改采用的新接线路的网卡,例如:改ETH=eth1 为ETH=eth2
(3)增加新线路的帐号和密码. 帐号密码一般是保存在/etc/ppp/chap-secrets 和pap-secrets
我们只需要在最后增加新的用户名2和密码2即可.
/etc/ppp/chap-secrets文件一般是这样的:
Secrets for authentication using CHAP
client serversecret IP addresses
“用户名1” * “密码1”
“用户名2” * “密码2”
“用户名n” * “密码n”
方法二:
重复执行pppoe-setup,选择不同的网卡和对应的账号密码配置。配置完成后,修改PIDFILE,默认生成的PIDFILE都是相同的,需要用0,1,2...对应区分。
启动脚本
#!/bin/bash
interfaces=(‘ppp0’ ‘ppp1’)
tables=(‘100’ ‘101’)
#set -x
index=0
for interface in ${interfaces[@]}
do
#sleep 60s
echo "date
restarting interface $interface …"
/sbin/ifdown $interface
/sbin/ifup $interface
_ip=/sbin/ip addr show $interface | grep peer | awk '{print $2}'
_gateway=/sbin/ip addr show $interface | grep peer | awk '{print $4}' | sed 's/\/32//'
/sbin/ip route flush table ${tables[index]}
/sbin/ip route add default via $_gateway dev $interface src $_ip table ${tables[index]}
/sbin/ip rule show | grep “lookup ${tables[index]}” | awk ‘{print $3}’ | xargs -I{} /sbin/ip rule del from {} table ${tables[index]}
/sbin/ip rule add from $_ip table ${tables[index]}
echo "date
route table ${tables[index]}"
/sbin/ip route list table ${tables[index]}
((index+=1))
sleep 5s
done