Как подключиться к beeline в Arch Linux?



Установка необходимых пакетов

pacman -S iptables xl2tpd dhclient

Замена dhcpcd на dhclient в Arch Linux

pacman -S dhclient
cat << EOF >> /etc/netctl/hooks/dhcp
#!/bin/sh
DHCPClient='dhclient'
EOF

Файл /etc/dhclient-exit-hooks

#!/bin/sh
 
if [ x"$new_rfc3442_classless_static_routes" != x"" ]; then
    if [ x"$reason" == x"BOUND" -o x"$reason" == x"REBOOT" ]; then
        rfc_routes=($new_rfc3442_classless_static_routes)

        for(( i=0; i < ${#rfc_routes[@]}; )); do
            net_length=${rfc_routes[$i]}
            ((i++))

            net_address=(0 0 0 0)
            for(( j=0; j < $[$net_length / 8 + ($net_length % 8 ? 1 : 0)]; j++, i++)); do
                net_address[$j]=${rfc_routes[$i]}
            done

            gateway=(0 0 0 0)
            for (( j=0; j < 4; j++, i++ )); do
                gateway[$j]=${rfc_routes[$i]}
            done

            old_IFS="$IFS"
            IFS='.'

            if [[ -n "$(which ip 2>/dev/null)" ]]; then
                ip route replace "${net_address[*]}/$net_length" via "${gateway[*]}"
            else
                if [[ -n "$(which route 2>/dev/null)" ]]; then
                    if [ x"$net_length" == x"32" ]; then
                        route add -host "${net_address[*]}" gw "${gateway[*]}"
                    else
                        route add -net "${net_address[*]}/$net_length" gw "${gateway[*]}"
                    fi
                fi
            fi

            IFS="$old_IFS"
        done
    fi
fi
 
 
if [ x"$new_ms_classless_static_routes" != x"" ]; then
    if [ x"$reason" == x"BOUND" -o x"$reason" == x"REBOOT" ]; then
        ms_routes=($new_ms_classless_static_routes)

        for(( i=0; i < ${#ms_routes[@]}; )); do
            net_length=${ms_routes[$i]}
            ((i++))

            net_address=(0 0 0 0)
            for(( j=0; j < $[$net_length / 8 + ($net_length % 8 ? 1 : 0)]; j++, i++)); do
                net_address[$j]=${ms_routes[$i]}
            done

            gateway=(0 0 0 0)
            for (( j=0; j < 4; j++, i++ )); do
                gateway[$j]=${ms_routes[$i]}
            done

            old_IFS="$IFS"
            IFS='.'

            if [[ -n "$(which ip 2>/dev/null)" ]]; then
                ip route replace "${net_address[*]}/$net_length" via "${gateway[*]}"
            else
                if [[ -n "$(which route 2>/dev/null)" ]]; then
                    if [ x"$net_length" == x"32" ]; then
                        route add -host "${net_address[*]}" gw "${gateway[*]}"
                    else
                        route add -net "${net_address[*]}/$net_length" gw "${gateway[*]}"
                    fi
                fi
            fi

            IFS="$old_IFS"
        done
    fi
fi

Устанавливаем права на выполнение

chmod a+x /etc/dhclient-exit-hooks

Файл /etc/dhclient.conf

timeout 60;
retry 60;
reboot 10;
select-timeout 5;
initial-interval 2;

send host-name "my.pc";

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
option ms-classless-static-routes code 249 = array of unsigned integer 8;

request subnet-mask, broadcast-address, time-offset, routers, static-routes,
   domain-name-servers, interface-mtu,
   rfc3442-classless-static-routes, ms-classless-static-routes;

Файл /etc/xl2tpd/xl2tpd.conf

[global]
access control = yes
auth file = /etc/ppp/chap-secrets
[lac beeline]
lns = tp.internet.beeline.ru
redial = yes
redial timeout = 5
require chap = yes
require authentication = no
name = <LOGIN BEELINE>
ppp debug = no
pppoptfile = /etc/ppp/peers/options.xl2tpd
require pap = no
autodial = yes
tx bps = 1000000000

Файл /etc/ppp/peers/options.xl2tpd

lcp-echo-interval 10
lcp-echo-failure 2
name <LOGIN BEELINE>
remotename l2tp
ipparam corbina
mtu 1460
nodeflate
nobsdcomp
persist
maxfail 0
nopcomp
noaccomp
noauth
noproxyarp

Файл /etc/ppp/chap-secrets

<LOGIN BEELINE> * <PASSWORD>

Файл /etc/ppp/options

logfile /var/log/xl2tpd.log
mru 1460
mtu 1460
noauth
nodeflate
nobsdcomp
novj
novjccomp
noipx
nomp
lcp-echo-failure 10
lcp-echo-interval 60

Файл /etc/ppp/ip-up.d/0010beeline-up.sh

#!/bin/sh

# Parameters: interface-name tty-device speed local-IP-address remote-IP-address ipparam
GW=`/usr/bin/ip route | /usr/bin/grep default | /usr/bin/awk '{ print $3 }'`
echo $GW > /tmp/gateway

/usr/bin/ip route del default
/usr/bin/ip route add $5 via $GW

# Route DNS
for i in $(grep "^nameserver" /etc/resolv.conf | awk '{print $2}'); do
   /usr/bin/ip route add $i via $GW
done

# Route tp.internet.beeline.ru
for i in $(/usr/bin/host tp.internet.beeline.ru | /usr/bin/awk '{print $4}' | /usr/bin/xargs); do
   /usr/bin/ip route add $i via $GW
done

/usr/bin/ip route add default dev $1

# Для шлюза
/usr/bin/iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

/usr/bin/iptables -t nat -F
/usr/bin/iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.0.0/24 ! -d 192.168.0.0/24 -j SNAT --to-source $4

Файл /etc/ppp/ip-down.d/0010beeline-down.sh

#!/bin/sh

GW=`cat /tmp/gateway`

/usr/bin/ip route del default
/usr/bin/ip route add default via $GW

# Для шлюза
/usr/bin/iptables -t nat -F
/usr/bin/iptables -t nat -A POSTROUTING -o enp2s1 -s 192.168.0.0/24 ! -d 192.168.0.0/24 -j MASQUERADE