Добрый день.
Структура сети следующая. Имеется неттоп Lenovo Q190 в качестве домашнего сервера, с установленной Ubuntu 12.04.
Провайдер раздает локальную сеть по статическому ip, а доступ в интернет через VPN-соединение. Поскольку у сервера нет монитора, то общение происходит по SSH. А настройка соединения производится не через NetworkManager, а с помощью pppd, ниже дам все настройки.
На сервере поднят локальный VPN сервер и есть 1-2 клиента, которые запитываются интернетом через меня. Дома к серверу по wi-fi подключены 2 ноутбука.
Все настройки осуществлялись при помощи мануалов с
https://help.ubuntu.ru/:
https://help.ubuntu.ru/wiki/настройка_сети_вручнуюhttps://help.ubuntu.ru/wiki/wifi_apПроблема в следующем: если начать качать через торент, либо одновременно на 2х ноутах смотреть видео с youtube в высоком качестве (720р), то соединение с VPN провайдера падает. И лечится, как правило, только перезагрузкой сервера. Как быть? Или это проблемы на стороне провайдера?
ifconfig
br0 Link encap:Ethernet HWaddr 20:16:d8:c3:44:47
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::2216:d8ff:fec3:4447/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:131663 errors:0 dropped:0 overruns:0 frame:0
TX packets:188842 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:16185717 (16.1 MB) TX bytes:218637820 (218.6 MB)
eth0 Link encap:Ethernet HWaddr 50:af:73:21:d9:f4
inet addr:172.17.2.20 Bcast:172.17.2.255 Mask:255.255.255.0
inet6 addr: fe80::52af:73ff:fe21:d9f4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:365962 errors:0 dropped:26829 overruns:0 frame:0
TX packets:184713 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:237327062 (237.3 MB) TX bytes:25509185 (25.5 MB)
lo Link encap:Локальная петля (Loopback)
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:42 errors:0 dropped:0 overruns:0 frame:0
TX packets:42 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3452 (3.4 KB) TX bytes:3452 (3.4 KB)
mon.wlan0 Link encap:UNSPEC HWaddr 20-16-D8-C3-44-47-00-00-00-00-00-00-00-00-00-00
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7134 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1095750 (1.0 MB) TX bytes:0 (0.0 B)
ppp0 Link encap:Протокол PPP (Point-to-Point Protocol)
inet addr:10.16.96.15 P-t-P:10.128.0.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1476 Metric:1
RX packets:192493 errors:0 dropped:0 overruns:0 frame:0
TX packets:133021 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:220525772 (220.5 MB) TX bytes:16004788 (16.0 MB)
wlan0 Link encap:Ethernet HWaddr 20:16:d8:c3:44:47
inet6 addr: fe80::2216:d8ff:fec3:4447/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:131651 errors:0 dropped:0 overruns:0 frame:0
TX packets:190103 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:18029257 (18.0 MB) TX bytes:222266769 (222.2 MB)
cat /etc/network/interfaces
auto lo
iface lo inet loopback
#iface eth0 inet dhcp
iface eth0 inet static
address 172.17.2.20
netmask 255.255.255.0
gateway 172.17.2.1
dns-nameservers 8.8.8.8
auto eth0
# Автостарт vpn(pptp) соединения
iface ppp0 inet ppp
provider TTK-vpn
auto ppp0
auto wlan0 br0
# Беспроводной интерфейс
iface wlan0 inet manual
pre-up iw dev wlan0 del
pre-up iw phy phy0 interface add wlan0 type __ap
# Мост.
iface br0 inet static
address 192.168.0.1
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
bridge_ports eth1 wlan0
cat /etc/ppp/pptpd-options
###############################################################################
# $Id$
#
# Sample Poptop PPP options file /etc/ppp/pptpd-options
# Options used by PPP when a connection arrives from a client.
# This file is pointed to by /etc/pptpd.conf option keyword.
# Changes are effective on the next connection. See "man pppd".
#
# You are expected to change this file to suit your system. As
# packaged, it requires PPP 2.4.2 and the kernel MPPE module.
###############################################################################
# Authentication
auth
# Name of the local system for authentication purposes
# (must match the second field in /etc/ppp/chap-secrets entries)
name pptpd
# Optional: domain name to use for authentication
# domain mydomain.net
# Strip the domain prefix from the username before authentication.
# (applies if you use pppd with chapms-strip-domain patch)
#chapms-strip-domain
# Encryption
# Debian: on systems with a kernel built with the package
# kernel-patch-mppe >= 2.4.2 and using ppp >= 2.4.2, ...
# {{{
refuse-pap
refuse-chap
refuse-mschap
# Require the peer to authenticate itself using MS-CHAPv2 [Microsoft
# Challenge Handshake Authentication Protocol, Version 2] authentication.
#require-mschap-v2
# Require MPPE 128-bit encryption
# (note that MPPE requires the use of MSCHAP-V2 during authentication)
#require-mppe-128
# }}}
# Network and Routing
# If pppd is acting as a server for Microsoft Windows clients, this
# option allows pppd to supply one or two DNS (Domain Name Server)
# addresses to the clients. The first instance of this option
# specifies the primary DNS address; the second instance (if given)
# specifies the secondary DNS address.
# Attention! This information may not be taken into account by a Windows
# client. See KB311218 in Microsoft's knowledge base for more information.
#ms-dns 10.0.0.1
#ms-dns 10.0.0.2
# If pppd is acting as a server for Microsoft Windows or "Samba"
# clients, this option allows pppd to supply one or two WINS (Windows
# Internet Name Services) server addresses to the clients. The first
# instance of this option specifies the primary WINS address; the
# second instance (if given) specifies the secondary WINS address.
#ms-wins 10.0.0.3
#ms-wins 10.0.0.4
# Add an entry to this system's ARP [Address Resolution Protocol]
# table with the IP address of the peer and the Ethernet address of this
# system. This will have the effect of making the peer appear to other
# systems to be on the local ethernet.
# (you do not need this if your PPTP server is responsible for routing
# packets to the clients -- James Cameron)
#proxyarp
# Debian: do not replace the default route
nodefaultroute
# Logging
# Enable connection debugging facilities.
# (see your syslog configuration for where pppd sends to)
#debug
# Print out all the option values which have been set.
# (often requested by mailing list to verify options)
dump
logfile /var/log/pptpd.log
# Miscellaneous
# Create a UUCP-style lock file for the pseudo-tty to ensure exclusive
# access.
#lock
# Disable BSD-Compress compression
#nobsdcomp
noipdefault
nopersist
debug
cat /etc/pptpd.conf
###############################################################################
# $Id$
#
# Sample Poptop configuration file /etc/pptpd.conf
#
# Changes are effective when pptpd is restarted.
###############################################################################
# TAG: ppp
# Path to the pppd program, default '/usr/sbin/pppd' on Linux
#
#ppp /usr/sbin/pppd
# TAG: option
# Specifies the location of the PPP options file.
# By default PPP looks in '/etc/ppp/options'
#
option /etc/ppp/pptpd-options
# TAG: debug
# Turns on (more) debugging to syslog
#
#debug
# TAG: stimeout
# Specifies timeout (in seconds) on starting ctrl connection
#
# stimeout 10
# TAG: noipparam
# Suppress the passing of the client's IP address to PPP, which is
# done by default otherwise.
#
#noipparam
# TAG: logwtmp
# Use wtmp(5) to record client connections and disconnections.
#
logwtmp
# TAG: bcrelay <if>
# Turns on broadcast relay to clients from interface <if>
#
# bcrelay eth0
# TAG: localip
# TAG: remoteip
# Specifies the local and remote IP address ranges.
#
# Any addresses work as long as the local machine takes care of the
# routing. But if you want to use MS-Windows networking, you should
# use IP addresses out of the LAN address space and use the proxyarp
# option in the pppd options file, or run bcrelay.
#
# You can specify single IP addresses seperated by commas or you can
# specify ranges, or both. For example:
#
# 192.168.0.234,192.168.0.245-249,192.168.0.254
#
# IMPORTANT RESTRICTIONS:
#
# 1. No spaces are permitted between commas or within addresses.
#
# 2. If you give more IP addresses than MAX_CONNECTIONS, it will
# start at the beginning of the list and go until it gets
# MAX_CONNECTIONS IPs. Others will be ignored.
#
# 3. No shortcuts in ranges! ie. 234-8 does not mean 234 to 238,
# you must type 234-238 if you mean this.
#
# 4. If you give a single localIP, that's ok - all local IPs will
# be set to the given one. You MUST still give at least one remote
# IP for each simultaneous client.
#
# (Recommended)
localip 172.17.2.20
remoteip 10.231.56.2-10
cat /etc/ppp/peers/TTK-vpn
# При разрыве соединения - переподключаться снова.
persist
# Максимальное количество неудачных попыток подключения. 0 - бесконечно.
maxfail 0
# Значение MTU
mtu 1476
# Ваш логин.
name my_provider_name
# Не быть шлюзом по умолчанию
#nodefaultroute
# Быть шлюзом по умолчанию
defaultroute
# Заменить шлюз по умолчанию если он был
replacedefaultroute
# Имя удаленного сервера (для нас), может быть любым.
remotename ttkvpn
# Команда запуска pptp.
# Адрес сервера - может быть как IP адресом, так и доменным именем, например vpn.foo.bar
pty "pptp 172.22.0.248 --nolaunchpppd"
Для доступа к локальным ресурсам используется дополнительная маршрутизация
cat /etc/ppp/ip-up.d/my_route
#! /bin/sh
#
route del default
route add default ppp0 # Имя ppp-подключения.
# тут - необходимые маршруты, например:
# example
#route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth0
route add -net 172.16.0.0 netmask 255.240.0.0 gw 172.17.2.1 dev eth0
route add -net 195.20.194.22 netmask 255.255.255.255 gw 172.17.2.1 dev eth0
route add -net 195.20.194.6 netmask 255.255.255.255 gw 172.17.2.1 dev eth0
route add -net 195.20.195.94 netmask 255.255.255.255 gw 172.17.2.1 dev eth0
route add -net 192.168.0.0 netmask 255.255.0.0 gw 172.17.2.1 dev eth0
route add -net 195.20.195.27 netmask 255.255.255.255 gw 172.17.2.1 dev eth0
route add -net 195.20.194.7 netmask 255.255.255.255 gw 172.17.2.1 dev eth0
Сначала хотел настроить iptable по уму, но не хватило знаний и усидчивости, поэтому сделал так как заработало.
cat /etc/network/if-up.d/my_iptable
#! /bin/sh
#
#######################
# Настройка интерфейсов
#######################
# Internet (Поменяйте на ваш интернет-интерфейс)
Inet_Interface="eth0"
# Lan (поменяйте на ваш интерфейс сетевого моста)
Lan_Interface="br0"
# Lo (локальный интефейс - петля)
Lo_Interface="lo"
# VPN (локальный интефейс - петля)
VPN_Interface="ppp0"
# Описываем путь до iptables
IPT="/sbin/iptables"
# Цепочка POSTROUTING (таблица nat)
$IPT -t nat -A POSTROUTING -o $Inet_Interface -j MASQUERADE
$IPT -t nat -A POSTROUTING -o $VPN_Interface -j MASQUERADE
$IPT -t nat -A POSTROUTING -s 10.231.56.0/24 -o $Inet_Interface -j MASQUERADE
$IPT -t nat -A POSTROUTING -s 10.231.56.0/24 -o $VPN_Interface -j MASQUERADE
# Включаем перенаправление ipv4.
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "Firewall started"
exit 0