システムの準備
aptitude update 
      
        
        
        
      
     aptitude install openssh-server mc mtr tracert nano tcpdump bind9 pppoe freeradius radiusclient1 rcconf php5
      
      DNSサーバーのセットアップ
実施します
nano /etc/bind/named.conf.options
      
      ファイルの最後に追加します。
allow-transfer { none; }; 
      
        
        
        
      
     allow-query { 10.128.0.0/16; localhost; }; //   
      
        
        
        
      
     allow-recursion { 10.128.0.0/16; localhost; }; //   
      
        
        
        
      
     version "My ISP DNS"; //     
      
        
        
        
      
    
      
      DNSサーバーのchroot環境のセットアップを始めましょう。 DNSサーバーのルートファイルシステムのディレクトリを作成します-root-dns:
mkdir -p /root-dns/etc 
      
        
        
        
      
     mkdir /root-dns/dev 
      
        
        
        
      
     mkdir -p /root-dns/var/cache/bind 
      
        
        
        
      
     mkdir -p /root-dns/var/run/bind/run 
      
        
        
        
      
     /etc/init.d/bind9 stop 
      
        
        
        
      
     nano /etc/default/bind9
      
      行「OPTIONS = "を見つけて、置き換えました:
OPTIONS="-u bind -t /root-dns"
      
      mv /etc/bind /root-dns/etc 
      
        
        
        
      
     ln -s /root-dns/etc/bind /etc/bind 
      
        
        
        
      
     nano /etc/init.d/bind9 
      
        
        
        
      
    
      
      行「OPTIONS = "を見つけて、置き換えました:
OPTIONS="-u bind -t /root-dns"
      
      以下を開始します。
nano /etc/init.d/rsyslogd
      
      「RSYSLOGD_OPTIONS」が見つかり、置き換えられました。
RSYSLOGD_OPTIONS="-c3 -a /root-dns/dev/log"
      
      named.conf構成ファイルを編集および削除から保護します。
chattr +i /root-dns/etc/bind/named.conf
      
      ご注意 構成ファイルを編集する前に、「i」属性を削除することを忘れないでください(chattr -i ...)
mknod /root-dns/dev/null c 1 3 
      
        
        
        
      
     mknod /root-dns/dev/random c 1 8 
      
        
        
        
      
     chmod 666 /root-dns/dev/null /root-dns/dev/random 
      
        
        
        
      
     chown -R bind:bind /root-dns/var/* 
      
        
        
        
      
     chown -R bind:bind /root-dns/etc/bind 
      
        
        
        
      
     /etc/init.d/bind9 start 
      
        
        
        
      
    
      
      PPPoEサーバー
cd /tmp 
      
        
        
        
      
     apt-get build-dep pppoe 
      
        
        
        
      
     apt-get source pppoe 
      
        
        
        
      
     cd rp-pppoe-3.8/src 
      
        
        
        
      
     ./configure 
      
        
        
        
      
    
      
      以下を開始します。
nano config.h
      
      作成したconfig.hファイルで、次の行を置き換える必要があります。
/* #undef HAVE_LINUX_KERNEL_PPPOE */
      
      ライン上:
#define HAVE_LINUX_KERNEL_PPPOE 1
      
      私たちは実施します:
cd .. 
      
        
        
        
      
     ./debian/rules PLUGIN_PATH=/usr/lib/pppd/2.4.4/rp-pppoe.so 
      
        
        
        
      
     ./debian/rules binary 
      
        
        
        
      
     cd .. 
      
        
        
        
      
     dpkg -i pppoe_3.8-3_i386.deb 
      
        
        
        
      
    
      
      システム上のパッケージをフリーズして、自動的に更新されないようにします。
echo pppoe hold | dpkg —set-selections
      
      これ以降、少なくともシステムを更新するたびに、更新のリストを表示する必要があります。 脆弱性を解決するpppoeのアップデートが閉じられた場合、新しいソースからパッケージを再構築し、コマンドを使用してシステムからパッケージを削除する必要があります。
echo pppoe install | dpkg --set-selections
      
      これでPPPoEサーバーを含むパッケージがシステムにインストールされ、カーネルレベルのPPPoE接続をサポートできるようになりました。 このモードでサーバーを起動するには、前のセクションで説明したコマンドに-kオプションを追加します。pppoe-server -I eth1 -L 192.168.0.1 -k
以下を開始します。
nano /etc/ppp/pppoe-server-options
      
      挿入:
logfile /var/log/pppoe.log 
      
        
        
        
      
     debug 
      
        
        
        
      
     mtu 1472 
      
        
        
        
      
     mru 1472 
      
        
        
        
      
     auth 
      
        
        
        
      
     require-pap 
      
        
        
        
      
     #require-chap 
      
        
        
        
      
     default-asyncmap 
      
        
        
        
      
     ktune 
      
        
        
        
      
     lcp-echo-interval 20 
      
        
        
        
      
     lcp-echo-failure 2 
      
        
        
        
      
     ms-dns 10.128.0.1 
      
        
        
        
      
     plugin radius.so 
      
        
        
        
      
     plugin radattr.so 
      
        
        
        
      
     10.128.0.1: 
      
        
        
        
      
     nobsdcomp 
      
        
        
        
      
     noccp 
      
        
        
        
      
     noendpoint 
      
        
        
        
      
     noipdefault 
      
        
        
        
      
     noipx 
      
        
        
        
      
     novj 
      
        
        
        
      
     receive-all
      
      以下を開始します。
nano /etc/ppp/options
      
      config / etc / ppp / options:すべてを削除して、設定します:
lock
      
      以下を開始します。
nano /etc/init.d/pppoe-server 
      
        
        
        
      
    
      
      スクリプト:
#!/bin/bash 
      
        
        
        
      
     # init file for rp-pppoe server 
      
        
        
        
      
     # 
      
        
        
        
      
     # description: PPPOE kernel mode server 
      
        
        
        
      
     # 
      
        
        
        
      
     # processname: pppoe-server 
      
        
        
        
      
     # chkconfig: - 45 45 
      
        
        
        
      
     # source function library 
      
        
        
        
      
     #. /etc/rc.status 
      
        
        
        
      
     case "$1" in 
      
        
        
        
      
     start) 
      
        
        
        
      
     echo -n "Starting PPPOE server: " 
      
        
        
        
      
     /usr/sbin/pppoe-server -I eth0 -L 10.128.0.1 -R 10.128.1.1 -k 
      
        
        
        
      
     # eth0 — ,      
      
        
        
        
      
     #10.128.0.1 - IP PPPoE  
      
        
        
        
      
     #10.128.1.1 -  IP   
      
        
        
        
      
     #touch /var/lock/subsys/pppoed 
      
        
        
        
      
     #rc_status -v 
      
        
        
        
      
     ;; 
      
        
        
        
      
     stop) 
      
        
        
        
      
     echo -n "Shutting down PPPOE server: " 
      
        
        
        
      
     pkill pppoe-server 
      
        
        
        
      
     #rm -f /var/lock/subsys/pppoed 
      
        
        
        
      
     #rc_status -v 
      
        
        
        
      
     ;; 
      
        
        
        
      
     restart) 
      
        
        
        
      
     $0 stop 
      
        
        
        
      
     $0 start 
      
        
        
        
      
     ;; 
      
        
        
        
      
     status) 
      
        
        
        
      
     status pppoe-server 
      
        
        
        
      
     ;; 
      
        
        
        
      
     *) 
      
        
        
        
      
     echo "Usage: pppoed {start|stop|restart|status}" 
      
        
        
        
      
     exit 1 
      
        
        
        
      
     esac 
      
        
        
        
      
     exit 0 
      
        
        
        
      
    
      
      以下を開始します。
rcconf
      
      バインドを無効にします。 その後、再びそこに行き、彼がリストから完全に消えたことを確認します。 一番下にあり、次はpppoe-serverです。 彼らはこれとそれの両方を含んでいた。 アウト。
cd /root-dns/etc/bind 
      
        
        
        
      
     rndc-confgen -r /dev/urandom -a 
      
        
        
        
      
     chgrp bind rndc.key 
      
        
        
        
      
     chmod +r rndc.key 
      
        
        
        
      
     nano named.conf.options 
      
        
        
        
      
    
      
      ファイルの最後に、次を追加します。
controls { 
      
        
        
        
      
     inet 127.0.0.1 allow { localhost; } keys { rndc-key; }; 
      
        
        
        
      
     }; 
      
        
        
        
      
     include "/etc/bind/rndc.key"; 
      
        
        
        
      
    
      
      カーネルで転送を有効にし、iptablesルールフックを作成する必要があります。 構成は今のところテストされます。
パラメーターsysctl.conf、iptables、ネットワークインターフェイス設定
以下を開始します。
nano /etc/sysctl.conf
      
      コメントなし、そうでないものを追加:
net.ipv4.conf.default.rp_filter=1 
      
        
        
        
      
     net.ipv4.conf.all.rp_filter=1 
      
        
        
        
      
     net.ipv4.tcp_syncookies=1 
      
        
        
        
      
     net.ipv4.ip_forward=1 
      
        
        
        
      
     kernel.panic = 1 
      
        
        
        
      
     kernel.panic_on_oops = 1 
      
        
        
        
      
     kernel.panic_on_io_nmi = 1 
      
        
        
        
      
     kernel.panic_on_unrecovered_nmi = 1
      
      最後の4行は、さまざまなシステムクラッシュ時の再起動であり、再起動のために別の都市に移動しないようにします。 保存してから、iptablesのテスト構成を作成します。
iptables -t nat -F 
      
        
        
        
      
     iptables-save > /etc/firewall.conf 
      
        
        
        
      
     nano rc.local 
      
        
        
        
      
    
      
      rc.localで次のようになります。
ifconfig eth0 up 
      
        
        
        
      
     iptables-restore </etc/firewall.conf 
      
        
        
        
      
    
      
      次に、/ etc / network / interfacesを構成します-ここではeth0がローカルであることが判明しました。自動eth0を除き、何も書き込みません。 eth1について-インターネットの場合-静的な外部IPについて考えます。そうでない場合、SNATは使用できませんが、MASQUERADEのみが使用でき、システムの読み込みが難しくなります。
以下を開始します。
nano /etc/network/interfaces
      
      構成:
auto lo 
      
        
        
        
      
     iface lo inet loopback 
      
        
        
        
      
     auto eth0 
      
        
        
        
      
     auto eth1 
      
        
        
        
      
     
      
        
        
        
      
     allow-hotplug eth0 eth1 
      
        
        
        
      
     iface eth1 inet dhcp 
      
        
        
        
      
    
      
      このリストでは、eth1はNATおよびDHCP構成を介したインターネットです。
PPPoEサーバーのテスト実行
次に、半径のないPPPoEをテストする必要があります。 これを行うには、/ etc / ppp / pppoe-server-optionsのプラグインの2行にコメントします。
以下を開始します。
nano /etc/ppp/pppoe-server-options
      
      構成:
#plugin radius.so 
      
        
        
        
      
     #plugin radattr.so 
      
        
        
        
      
    
      
      以下を開始します。
nano /etc/ppp/pap-secrets
      
      最後に追加するか、内容を完全に置き換えます。
test * test 10.128.2.10
      
      pppoe-serverを起動します。
/etc/init.d/pppoe-server start
      
      サーバーを再起動し、PPPoEとインターネットを確認しました。 任意のクライアントで、PPPoE接続を作成し、ユーザー名とパスワードのテストを使用して接続します。 インターネットをクライアントと連携させるには、マスカレードを有効にする必要があります。
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
      
      動作しますか? さて、そのまま返されました:
iptables -t nat -F
      
      フリー半径
以下を開始します。
nano /etc/radiusclient/servers
      
      ファイルの内容を置き換えます。
127.0.0.1 my-isp-radius
      
      以下を開始します。
nano /etc/radiusclient/radiusclient.conf
      
      ファイルの内容を置き換えます。
auth_order radius,local 
      
        
        
        
      
     login_tries 4 
      
        
        
        
      
     login_timeout 60 
      
        
        
        
      
     nologin /etc/nologin 
      
        
        
        
      
     issue /etc/radiusclient/issue 
      
        
        
        
      
     # RADIUS settings 
      
        
        
        
      
     authserver localhost:1812 
      
        
        
        
      
     acctserver localhost:1812 
      
        
        
        
      
     servers /etc/radiusclient/servers 
      
        
        
        
      
     dictionary /etc/radiusclient/dictionary 
      
        
        
        
      
     login_radius /usr/sbin/login.radius 
      
        
        
        
      
     # RADIUS server 
      
        
        
        
      
     seqfile /var/run/radius.seq 
      
        
        
        
      
     mapfile /etc/radiusclient/port-id-map 
      
        
        
        
      
     default_realm 
      
        
        
        
      
     radius_timeout 10 
      
        
        
        
      
     radius_retries 3 
      
        
        
        
      
     login_local /bin/login 
      
        
        
        
      
    
      
      以下を開始します。
nano /etc/freeradius/radiusd.conf
      
      ファイルの内容を置き換えます。
prefix = /usr 
      
        
        
        
      
     exec_prefix = /usr 
      
        
        
        
      
     sysconfdir = /etc 
      
        
        
        
      
     localstatedir = /var 
      
        
        
        
      
     sbindir = ${exec_prefix}/sbin 
      
        
        
        
      
     logdir = /var/log/freeradius 
      
        
        
        
      
     raddbdir = /etc/freeradius 
      
        
        
        
      
     radacctdir = ${logdir}/radacct 
      
        
        
        
      
     #     . 
      
        
        
        
      
     confdir = ${raddbdir} 
      
        
        
        
      
     run_dir = ${localstatedir}/run/freeradius 
      
        
        
        
      
     #    . 
      
        
        
        
      
     libdir = ${exec_prefix}/lib 
      
        
        
        
      
     #  pid-.   . 
      
        
        
        
      
     pidfile = ${run_dir}/freeradius.pid 
      
        
        
        
      
     #        FreeRADIUS 
      
        
        
        
      
     user = freerad 
      
        
        
        
      
     group = freerad 
      
        
        
        
      
     #   ( )    . 
      
        
        
        
      
     max_request_time = 30 
      
        
        
        
      
     #       max_request_time 
      
        
        
        
      
     delete_blocked_requests = no 
      
        
        
        
      
     #   ( )   reply   NAS. 
      
        
        
        
      
     cleanup_delay = 5 
      
        
        
        
      
     #     .      
      
        
        
        
      
     #     256. 
      
        
        
        
      
     #        1024. 
      
        
        
        
      
     max_requests = 5120 
      
        
        
        
      
     #   ip .   RADIUS     
      
        
        
        
      
     #    ip . 
      
        
        
        
      
     bind_address = 127.0.0.1 
      
        
        
        
      
     #   FreeRADIUS  port.   , 
      
        
        
        
      
     #     /etc/services 
      
        
        
        
      
     port = 0 
      
        
        
        
      
     # / ip   dns . 
      
        
        
        
      
     #       . 
      
        
        
        
      
     hostname_lookups = no 
      
        
        
        
      
     # /     . 
      
        
        
        
      
     allow_core_dumps = no 
      
        
        
        
      
     #    . 
      
        
        
        
      
     regular_expressions = yes 
      
        
        
        
      
     extended_expressions = yes 
      
        
        
        
      
     #   User-Name     . 
      
        
        
        
      
     log_stripped_names = no 
      
        
        
        
      
     #     . 
      
        
        
        
      
     log_auth = yes 
      
        
        
        
      
     #      . 
      
        
        
        
      
     # log_auth_badpass -    
      
        
        
        
      
     # log_auth_goodpass -   
      
        
        
        
      
     log_auth_badpass = yes 
      
        
        
        
      
     log_auth_goodpass = no 
      
        
        
        
      
     # /  . 
      
        
        
        
      
     usercollide = no 
      
        
        
        
      
     #   /     . 
      
        
        
        
      
     lower_user = no 
      
        
        
        
      
     lower_pass = no 
      
        
        
        
      
     #     / . 
      
        
        
        
      
     nospace_user = no 
      
        
        
        
      
     nospace_pass = no 
      
        
        
        
      
     #     DoS . 
      
        
        
        
      
     security { 
      
        
        
        
      
     #      RADIUS . 
      
        
        
        
      
     max_attributes = 200 
      
        
        
        
      
     #  ( )   Access-Reject . 
      
        
        
        
      
     reject_delay = 1 
      
        
        
        
      
     #     Status-Server 
      
        
        
        
      
     status_server = no 
      
        
        
        
      
     } 
      
        
        
        
      
     #   RADIUS . 
      
        
        
        
      
     #    . 
      
        
        
        
      
     $INCLUDE ${confdir}/clients.conf 
      
        
        
        
      
     #  snmp . 
      
        
        
        
      
     snmp=no 
      
        
        
        
      
     #   . 
      
        
        
        
      
     thread pool { 
      
        
        
        
      
     #    . 
      
        
        
        
      
     start_servers = 5 
      
        
        
        
      
     #    . 
      
        
        
        
      
     max_servers = 32 
      
        
        
        
      
     #    . 
      
        
        
        
      
     min_spare_servers = 3 
      
        
        
        
      
     max_spare_servers = 10 
      
        
        
        
      
     
      
        
        
        
      
     #    .       
      
        
        
        
      
     # RADIUS .   300,     
      
        
        
        
      
     #   . 
      
        
        
        
      
     max_requests_per_server = 0 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     #    . 
      
        
        
        
      
     modules { 
      
        
        
        
      
     #  PAP . 
      
        
        
        
      
     #      PAP . 
      
        
        
        
      
     # encryption_scheme      . 
      
        
        
        
      
     # clear -    . 
      
        
        
        
      
     pap { 
      
        
        
        
      
     encryption_scheme = clear 
      
        
        
        
      
     } 
      
        
        
        
      
     #  CHAP . 
      
        
        
        
      
     #      CHAP . 
      
        
        
        
      
     # authtype       Auth-Type=CHAP 
      
        
        
        
      
     chap { 
      
        
        
        
      
     authtype = CHAP 
      
        
        
        
      
     } 
      
        
        
        
      
     #   . 
      
        
        
        
      
     # ..   . 
      
        
        
        
      
     preprocess { 
      
        
        
        
      
     # huntgroups -   .  huntgoups. 
      
        
        
        
      
     # hints - . 
      
        
        
        
      
     huntgroups = ${confdir}/huntgroups 
      
        
        
        
      
     hints = ${confdir}/hints 
      
        
        
        
      
     
      
        
        
        
      
     #  Cisco VSA. 
      
        
        
        
      
     with_cisco_vsa_hack = no 
      
        
        
        
      
     } 
      
        
        
        
      
     #  Microsoft CHAP . 
      
        
        
        
      
     #      Microsoft CHAP v2 
      
        
        
        
      
     # authtype       Auth-Type=MS-CHAP 
      
        
        
        
      
     # use_mppe = no     VPN . 
      
        
        
        
      
     mschap { 
      
        
        
        
      
     authtype = MS-CHAP 
      
        
        
        
      
     use_mppe = no 
      
        
        
        
      
     } 
      
        
        
        
      
     #   Livingston RADIUS . 
      
        
        
        
      
     # usersfile    . 
      
        
        
        
      
     #          . 
      
        
        
        
      
     # acctusersfile     (). 
      
        
        
        
      
     # compat - .     FreeRADIUS  . 
      
        
        
        
      
     files { 
      
        
        
        
      
     usersfile = ${confdir}/users 
      
        
        
        
      
     compat = no 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     #     . 
      
        
        
        
      
     detail { 
      
        
        
        
      
     detailfile = ${radacctdir}/%{Client-IP-Address}/detail-%Y%m%d 
      
        
        
        
      
     detailperm = 0600 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     #     . 
      
        
        
        
      
     detail auth_log { 
      
        
        
        
      
     detailfile = ${radacctdir}/%{Client-IP-Address}/auth-detail-%Y%m%d 
      
        
        
        
      
     detailperm = 0600 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     #    reply . 
      
        
        
        
      
     detail reply_log { 
      
        
        
        
      
     detailfile = ${radacctdir}/%{Client-IP-Address}/reply-detail-%Y%m%d 
      
        
        
        
      
     detailperm = 0600 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     #      . 
      
        
        
        
      
     #  NAS   Acct-Session-ID. 
      
        
        
        
      
     # key     Acct-Session-ID 
      
        
        
        
      
     acct_unique { 
      
        
        
        
      
     key = "User-Name, Acct-Session-Id, NAS-IP-Address, Client-IP-Address, NAS-Port-Id" 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     #       
      
        
        
        
      
     #     cakesql.conf 
      
        
        
        
      
     #$INCLUDE ${confdir}/sql.conf 
      
        
        
        
      
     #$INCLUDE ${confdir}/sql/mysql/counter.conf 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     #  
      
        
        
        
      
     #      preprocess 
      
        
        
        
      
     #    . 
      
        
        
        
      
     #  chap mschap  chap  mschap . 
      
        
        
        
      
     authorize { 
      
        
        
        
      
     preprocess 
      
        
        
        
      
     chap 
      
        
        
        
      
     mschap 
      
        
        
        
      
     #     . 
      
        
        
        
      
     # auth_log 
      
        
        
        
      
     files 
      
        
        
        
      
     #sql 
      
        
        
        
      
     } 
      
        
        
        
      
     #  
      
        
        
        
      
     #    ,  . 
      
        
        
        
      
     authenticate { 
      
        
        
        
      
     Auth-Type PAP { 
      
        
        
        
      
     pap 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     Auth-Type CHAP { 
      
        
        
        
      
     chap 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     Auth-Type MS-CHAP { 
      
        
        
        
      
     mschap 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     } 
      
        
        
        
      
     #   . 
      
        
        
        
      
     preacct { 
      
        
        
        
      
     preprocess 
      
        
        
        
      
     } 
      
        
        
        
      
     #   . 
      
        
        
        
      
     accounting { 
      
        
        
        
      
     #  Acct-Session-Id   NAS      . 
      
        
        
        
      
     acct_unique 
      
        
        
        
      
     #   detail . 
      
        
        
        
      
     detail 
      
        
        
        
      
     #      
      
        
        
        
      
     #sql 
      
        
        
        
      
     } 
      
        
        
        
      
     #    reply-. 
      
        
        
        
      
     post-auth { 
      
        
        
        
      
     #      . 
      
        
        
        
      
     reply_log 
      
        
        
        
      
     } 
      
        
        
        
      
     log { 
      
        
        
        
      
     destination = files 
      
        
        
        
      
     file = ${logdir}/radius.log 
      
        
        
        
      
     syslog_facility = daemon 
      
        
        
        
      
     stripped_names = no 
      
        
        
        
      
     auth = no 
      
        
        
        
      
     auth_badpass = no 
      
        
        
        
      
     auth_goodpass = no 
      
        
        
        
      
     } 
      
        
        
        
      
    
      
      以下を開始します。
nano /etc/freeradius/clients.conf
      
      ファイルの内容を置き換えます。
client localhost { 
      
        
        
        
      
     ipaddr = 127.0.0.1 
      
        
        
        
      
     secret = my-isp-radius 
      
        
        
        
      
     require_message_authenticator = no 
      
        
        
        
      
     nastype = other 
      
        
        
        
      
     } 
      
        
        
        
      
    
      
      以下を開始します。
nano /etc/freeradius/users
      
      構成:
steve Cleartext-Password := "testing" 
      
        
        
        
      
     Service-Type = Framed-User, 
      
        
        
        
      
     Framed-Protocol = PPP, 
      
        
        
        
      
     Framed-IP-Address = 10.128.13.3, 
      
        
        
        
      
     Framed-IP-Netmask = 255.255.0.0, 
      
        
        
        
      
     Framed-Routing = Broadcast-Listen, 
      
        
        
        
      
     Framed-Filter-Id = "std.ppp", 
      
        
        
        
      
     Framed-MTU = 1500, 
      
        
        
        
      
     Framed-Compression = Van-Jacobsen-TCP-IP 
      
        
        
        
      
     
      
        
        
        
      
     #        
      
        
        
        
      
     
      
        
        
        
      
     DEFAULT Framed-Protocol == PPP 
      
        
        
        
      
     Framed-Protocol = PPP, 
      
        
        
        
      
     Framed-Compression = Van-Jacobson-TCP-IP 
      
        
        
        
      
     
      
        
        
        
      
     DEFAULT Hint == "CSLIP" 
      
        
        
        
      
     Framed-Protocol = SLIP, 
      
        
        
        
      
     Framed-Compression = Van-Jacobson-TCP-IP 
      
        
        
        
      
     
      
        
        
        
      
     DEFAULT Hint == "SLIP" 
      
        
        
        
      
     Framed-Protocol = SLIP 
      
        
        
        
      
    
      
      一般に、将来的にはMySQLでバンドルを構成する必要がありますが、この段階では重要ではありません。 ユーザーを追加するとき、Freeradiusを再起動する必要があります。
/etc/init.d/freeradius restart
      
      ここで、トラフィックシェーピングに対処する必要があります。 アイデアは、速度をユーザーごとに個別に調整し、属性としてRadiusサーバーからNATサーバーに送信することです。 なんで? そのため、後で構造を拡張し、複数のNAS間で負荷を分散することができました。
トラフィックシェーピング
だから、準備。 Wondershaperをインストールします。
aptitude install wondershaper
      
      このパッケージは、CBQ / HTBの優先順位付けで機能する単一のスクリプトであり、健全な呼び出し形式です。 必要に応じて、実装前に作業をテストできます。
wondershaper ppp0 512 512
      
      当然、ppp0は存在し、クライアントがサーバーに接続した結果である必要があります。 コマンドが完了すると、クライアントのWebブラウザーは、 speedtest.netなど、速度を測定する任意のサイトに移動し、シェーパーで切断されていることを確認できます。 クライアントから切断せずに(つまり、キック)設定をリセットするには、次のようにします。
wondershaper clear ppp0
      
      そして、速度が再び正常であることを確認します(つまり、WANインターフェイスの「ビッグブラザー」から取得した速度に等しくなります。速度制限の追加は、次の場合に表示される単純なファイルパーサー/var/run/radattr.ppp* ppp接続に成功し、RadiusサーバーからPPPoEサーバーに渡されるすべての属性が含まれます。属性を処理します。追加の属性ファイル/ etc / freeradius /辞書の内容をこれで補完します。
以下を開始します。
nano /etc/freeradius/dictionary
      
      構成:
# Limit session traffic 
      
        
        
        
      
     ATTRIBUTE Session-Octets-Limit 227 integer 
      
        
        
        
      
     # What to assume as limit - 0 in+out, 1 in, 2 out, 3 max(in,out) 
      
        
        
        
      
     ATTRIBUTE Octets-Direction 228 integer 
      
        
        
        
      
     # Connection Speed Limit 
      
        
        
        
      
     ATTRIBUTE PPPD-Upstream-Speed-Limit 230 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Downstream-Speed-Limit 231 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Upstream-Speed-Limit-1 232 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Downstream-Speed-Limit-1 233 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Upstream-Speed-Limit-2 234 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Downstream-Speed-Limit-2 235 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Upstream-Speed-Limit-3 236 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Downstream-Speed-Limit-3 237 integer 
      
        
        
        
      
     ATTRIBUTE Acct-Interim-Interval 85 integer
      
      さらに、これらの同じ属性をRaduisclient辞書に追加する必要があります。 / etc / radiusclient /辞書を編集し、最後に同じものを追加します:
以下を開始します。
nano /etc/radiusclient/dictionary
      
      構成:
# Limit session traffic 
      
        
        
        
      
     ATTRIBUTE Session-Octets-Limit 227 integer 
      
        
        
        
      
     # What to assume as limit - 0 in+out, 1 in, 2 out, 3 max(in,out) 
      
        
        
        
      
     ATTRIBUTE Octets-Direction 228 integer 
      
        
        
        
      
     # Connection Speed Limit 
      
        
        
        
      
     ATTRIBUTE PPPD-Upstream-Speed-Limit 230 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Downstream-Speed-Limit 231 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Upstream-Speed-Limit-1 232 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Downstream-Speed-Limit-1 233 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Upstream-Speed-Limit-2 234 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Downstream-Speed-Limit-2 235 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Upstream-Speed-Limit-3 236 integer 
      
        
        
        
      
     ATTRIBUTE PPPD-Downstream-Speed-Limit-3 237 integer 
      
        
        
        
      
     ATTRIBUTE Acct-Interim-Interval 85 integer 
      
        
        
        
      
    
      
      すべてが順調です。今、彼ら(FreeRadiusとRadiusClient)はお互いを理解します。 したがって、freeradiusユーザーの設定では、着信速度と発信速度の制限を示す追加の行が表示されます(ただし、必須ではありません)。 例:/ etc / freeradius /変更を伴うユーザー:
以下を開始します。
nano /etc/freeradius/users
      
      構成:
steve Cleartext-Password := "testing" 
      
        
        
        
      
     Service-Type = Framed-User, 
      
        
        
        
      
     Framed-Protocol = PPP, 
      
        
        
        
      
     Framed-IP-Address = 10.128.13.3, 
      
        
        
        
      
     Framed-IP-Netmask = 255.255.0.0, 
      
        
        
        
      
     Framed-Routing = Broadcast-Listen, 
      
        
        
        
      
     Framed-Filter-Id = "std.ppp", 
      
        
        
        
      
     Framed-MTU = 1500, 
      
        
        
        
      
     Framed-Compression = Van-Jacobsen-TCP-IP 
      
        
        
        
      
     PPPD-Downstream-Speed-Limit = 1024, 
      
        
        
        
      
     PPPD-Upstream-Speed-Limit = 1024 
      
        
        
        
      
     
      
        
        
        
      
     #        
      
        
        
        
      
     
      
        
        
        
      
     DEFAULT Framed-Protocol == PPP 
      
        
        
        
      
     Framed-Protocol = PPP, 
      
        
        
        
      
     Framed-Compression = Van-Jacobson-TCP-IP 
      
        
        
        
      
     
      
        
        
        
      
     DEFAULT Hint == "CSLIP" 
      
        
        
        
      
     Framed-Protocol = SLIP, 
      
        
        
        
      
     Framed-Compression = Van-Jacobson-TCP-IP 
      
        
        
        
      
     
      
        
        
        
      
     DEFAULT Hint == "SLIP" 
      
        
        
        
      
     Framed-Protocol = SLIP
      
      現在、NASは速度情報を受信していますが、処理方法はわかりません。 接続を確立するときに、渡された属性を解析する2つのスクリプトを作成します。
以下を開始します。
nano /etc/ppp/ip-up.d/0001shaper
      
      スクリプト:
#!/bin/sh 
      
        
        
        
      
     /root-scripts/shape-on $1 $5 
      
        
        
        
      
     exit 0
      
      以下を開始します。
nano /etc/ppp/ip-down.d/0001shaper
      
      スクリプト:
#!/bin/sh 
      
        
        
        
      
     /root-scripts/shape-off $1 $5 
      
        
        
        
      
     exit 0
      
      これらのリストからわかるように、シェーピングを適用およびキャンセルする特定のスクリプトが呼び出されます。 この瞬間から-より詳細に。 $ 1は渡されたインターフェイス名、つまりppp0です。たとえば、$ 5はFramed-IP、つまりPPPクライアントのIPアドレスです。 切望されたディレクトリを作成し、2つのファイルを入れます。
mkdir /root-scripts 
      
        
        
        
      
     nano /root-scripts/shape-on
      
      スクリプト:
#!/bin/sh 
      
        
        
        
      
     if [ -f /var/run/radattr.$1 ] 
      
        
        
        
      
     then 
      
        
        
        
      
     DOWNSPEED=`awk '/PPPD-Downstream-Speed-Limit/ {print $2}' /var/run/radattr.$1` 
      
        
        
        
      
     UPSPEED=`awk '/PPPD-Upstream-Speed-Limit/ {print $2}' /var/run/radattr.$1` 
      
        
        
        
      
     wondershaper $1 $DOWNSPEED $UPSPEED 
      
        
        
        
      
     fi 
      
        
        
        
      
     iptables -A FORWARD -s $2 -j ACCEPT 
      
        
        
        
      
     iptables -A INPUT -s $2 -j ACCEPT 
      
        
        
        
      
     iptables -t nat -A POSTROUTING -s $2 -o eth1 -j MASQUERADE 
      
        
        
        
      
    
      
      以下を開始します。
nano /root-scripts/shape-off
      
      スクリプト:
#!/bin/sh 
      
        
        
        
      
     iptables -D FORWARD -s $2 -j ACCEPT 
      
        
        
        
      
     iptables -D INPUT -s $2 -j ACCEPT 
      
        
        
        
      
     iptables -t nat -D POSTROUTING -s $2 -o eth1 -j MASQUERADE 
      
        
        
        
      
    
      
      以下を開始します。
chmod +x /root-scripts/*
      
      リストでは、eth1は依然としてWANインターフェースです。 したがって、結果として何が得られますか:クライアントはPPPサーバーに接続し、IPアドレスを受け取ります。 PPPクライアントインターフェイスでシェーピングを設定し、そのマスキングを含むスクリプトが自動的に呼び出されます。 切断されると、マスカレードルールも自動的に削除されます。 wondershaperを強制的にpppxから切断する必要はないようです。いずれの場合でも、マニュアルはそれについて黙っており、実際にはすべてが正常に機能します。
シンプルなiptables保護
ここで、iptablesとサーバーのセキュリティに少し注意を払いましょう。 /etc/firewall.confを置き換えます。
以下を開始します。
nano /etc/firewall.conf
      
      スクリプト:
#!/bin/bash 
      
        
        
        
      
     
      
        
        
        
      
     #reset all 
      
        
        
        
      
     iptables -F 
      
        
        
        
      
     iptables -Z 
      
        
        
        
      
     iptables -t nat -F 
      
        
        
        
      
     iptables -t nat -Z 
      
        
        
        
      
     
      
        
        
        
      
     #iface config 
      
        
        
        
      
     INET_IFACE="eth1" 
      
        
        
        
      
     LO_IFACE="lo" 
      
        
        
        
      
     LO_IP="127.0.0.1" 
      
        
        
        
      
     
      
        
        
        
      
     #kernel modules 
      
        
        
        
      
     modprobe ip_tables 
      
        
        
        
      
     modprobe ip_conntrack 
      
        
        
        
      
     modprobe iptable_filter 
      
        
        
        
      
     modprobe iptable_mangle 
      
        
        
        
      
     modprobe iptable_nat 
      
        
        
        
      
     modprobe ipt_LOG 
      
        
        
        
      
     modprobe ipt_limit 
      
        
        
        
      
     modprobe ipt_state 
      
        
        
        
      
     modprobe ipt_MASQUERADE 
      
        
        
        
      
     modprobe ip_conntrack_ftp 
      
        
        
        
      
     modprobe ip_conntrack_irc 
      
        
        
        
      
     modprobe ip_nat_ftp 
      
        
        
        
      
     modprobe ip_nat_irc 
      
        
        
        
      
     
      
        
        
        
      
     #default policy 
      
        
        
        
      
     iptables -P INPUT DROP 
      
        
        
        
      
     iptables -P OUTPUT DROP 
      
        
        
        
      
     iptables -P FORWARD DROP 
      
        
        
        
      
     
      
        
        
        
      
     #user chains 
      
        
        
        
      
     iptables -N bad_tcp_packets 
      
        
        
        
      
     iptables -N allowed 
      
        
        
        
      
     iptables -N tcp_packets 
      
        
        
        
      
     iptables -N udp_packets 
      
        
        
        
      
     iptables -N icmp_packets 
      
        
        
        
      
     iptables -N blocksshd 
      
        
        
        
      
     blocksshd --start 
      
        
        
        
      
     
      
        
        
        
      
     ###bad_tcp_packets chain 
      
        
        
        
      
     iptables -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK -m state --state NEW -j REJECT --reject-with tcp-reset 
      
        
        
        
      
     #iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "New not syn:" 
      
        
        
        
      
     iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP 
      
        
        
        
      
     
      
        
        
        
      
     ###allowed chain 
      
        
        
        
      
     iptables -A allowed -p TCP --syn -j ACCEPT 
      
        
        
        
      
     iptables -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT 
      
        
        
        
      
     iptables -A allowed -p TCP -j DROP 
      
        
        
        
      
     
      
        
        
        
      
     ###tcp_packets chain 
      
        
        
        
      
     iptables -A tcp_packets -p TCP -s 0/0 --dport 22 -j blocksshd 
      
        
        
        
      
     iptables -A tcp_packets -p TCP -s 0/0 --dport 22 -j allowed 
      
        
        
        
      
     iptables -A tcp_packets -p TCP -s 0/0 --dport 25 -j allowed 
      
        
        
        
      
     #iptables -A tcp_packets -p TCP -s 0/0 --dport 80 -j allowed 
      
        
        
        
      
     
      
        
        
        
      
     ###udp_packets chain 
      
        
        
        
      
     iptables -A udp_packets -p UDP -s 0/0 --destination-port 53 -j ACCEPT 
      
        
        
        
      
     
      
        
        
        
      
     ###icmp chain 
      
        
        
        
      
     iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT 
      
        
        
        
      
     iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT 
      
        
        
        
      
     
      
        
        
        
      
     ###input chain 
      
        
        
        
      
     iptables -A INPUT -p TCP -j bad_tcp_packets 
      
        
        
        
      
     iptables -A INPUT -p ALL -i $LO_IFACE -j ACCEPT 
      
        
        
        
      
     iptables -A INPUT -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT 
      
        
        
        
      
     iptables -A INPUT -p TCP -i $INET_IFACE -j tcp_packets 
      
        
        
        
      
     iptables -A INPUT -p UDP -i $INET_IFACE -j udp_packets 
      
        
        
        
      
     iptables -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets 
      
        
        
        
      
     #iptables -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level DEBUG --log-prefix "IPT INPUT packet died: " 
      
        
        
        
      
     
      
        
        
        
      
     ###forward chain 
      
        
        
        
      
     iptables -A FORWARD -p tcp -j bad_tcp_packets 
      
        
        
        
      
     #custom rules 
      
        
        
        
      
     #iptables -A FORWARD -s 10.128.0.10/32 -d 192.168.1.1/32 -p tcp -j ACCEPT 
      
        
        
        
      
     iptables -A FORWARD -s 10.128.0.0/16 -d 192.168.1.1/32 -p tcp -j DROP 
      
        
        
        
      
     #/custom rules 
      
        
        
        
      
     iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT 
      
        
        
        
      
     #iptables -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level DEBUG --log-prefix "IPT FORWARD packet died: " 
      
        
        
        
      
     
      
        
        
        
      
     ###OUTPUT chain 
      
        
        
        
      
     iptables -A OUTPUT -p tcp -j bad_tcp_packets 
      
        
        
        
      
     iptables -A OUTPUT -p ALL -j ACCEPT 
      
        
        
        
      
     #iptables -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level DEBUG --log-prefix "IPT OUTPUT packet died: " 
      
        
        
        
      
     
      
        
        
        
      
     ###mangle 
      
        
        
        
      
     iptables -t mangle -A POSTROUTING -o $INET_IFACE -j TTL --ttl-set 64 
      
        
        
        
      
    
      
      ここで何が見えますか? まず、強調表示されたルール。 実際の構成が異なるか、単に不必要なものとして不在になりますが、その意味は次のとおりです:サーバーゲートウェイがADSLモデムまたはWeb管理パネルを備えた同様のデバイスである場合、そこにログインするための巧妙なパスワードを作成する必要はありません。 代わりに、クライアントトンネルからのアクセスを禁止しますが、そのうちの1つを許可します-これは侵入可能なサービスアカウントになります。 もちろん、それは顧客向けではありません。 次。 ブルートフォースSSHサーバーに対する保護を含むコマンドが追加されました。 彼らの仕事のために、blockshdを設定する必要があります。
BlockSSHd
まず、 blocksshd.sourceforge.netからダウンロードして、どこかでファイルを解凍する必要があります。 ダウンロードにはwgetを使用しましたが、もちろん-パスはSourceForgeページからカットされました。つまり、ほとんどの場合異なるでしょう:
 cd /tmp 
      
        
        
        
      
     wget downloads.sourceforge.net/project/blocksshd/blocksshd/BlockSSHD%201.3/blocksshd-1.3.tar.gz?use_mirror=kent 
      
        
        
        
      
    
      
      このスクリプトはPerlで書かれており、動作するためにいくつかの追加モジュールが必要です。 それでは、モジュールに入りましょう:
cpan 
      
        
        
        
      
     upgrade 
      
        
        
        
      
     install Sys::Syslog 
      
        
        
        
      
     install Sys::Hostname 
      
        
        
        
      
     install File::Tail 
      
        
        
        
      
     install Tie::File 
      
        
        
        
      
     install Net::DNS 
      
        
        
        
      
     install Net::Subnets 
      
        
        
        
      
     install Getopt::Long 
      
        
        
        
      
     exit 
      
        
        
        
      
    
      
      このすべてを一挙にコピーしてターミナルにコピーアンドペーストする必要がないという事実に注意を促します。 これは、各操作が完了するまでに多くの時間を必要とし、インストール全体でCpanが質問をするためです。 すべての質問に対して、Enterキーを押すだけで、デフォルトではすべてが正しく、奇妙なことに十分です。
次に、blocksshdを解凍してインストールする必要があります。
cd /tmp 
      
        
        
        
      
     tar -xvzf ./blocksshd-1.3.tar.gz 
      
        
        
        
      
     cd blocksshd-1.3 
      
        
        
        
      
     make install 
      
        
        
        
      
    
      
      もちろん、マニュアルを書いている時点でのバージョンはまさにこれまたは多分どれでもあったので、コンソールにコピーせずにすべてを注意深く行う必要があります。 blocksshdの設定を編集するために残ります:
以下を開始します。
nano /etc/blocksshd.conf
      
      構成:
$cfg = { 
      
        
        
        
      
     os => 'linux', # Target OS - either linux or bsd 
      
        
        
        
      
     chain => 'blocksshd', # Name of iptables or pf chain 
      
        
        
        
      
     logfile => '/var/log/secure', # Log file to monitor 
      
        
        
        
      
     logcheck => '10', # How often to check the log file 
      
        
        
        
      
     max_attempts => '4', # Max number of failures 
      
        
        
        
      
     timeout => '360', # Reset IP count if no activity after time out in seconds 
      
        
        
        
      
     unblock => '1', # Enable unblocking 
      
        
        
        
      
     unblock_timeout => '43200', # Time in seconds after which to unblock a blocked IP address 
      
        
        
        
      
     restore_blocked => '0', # Turn on checking for previously blocked IPs 
      
        
        
        
      
     log_ips => '/etc/blocksshd.list', # Log file for blocked IPs 
      
        
        
        
      
     pid_file => '/var/run/blocksshd.pid', # Location of PID file 
      
        
        
        
      
     send_email => '0', # Enable the sending of email notifications 
      
        
        
        
      
     email => 'root', # Email address to send notifications 
      
        
        
        
      
     mail => '/bin/mail', # Location of mail binary 
      
        
        
        
      
     email_whois_lookup => '1', # enable whois lookup of the blocked ip addres in the sent email 
      
        
        
        
      
     whois => '/usr/bin/whois', # location of the whois binary 
      
        
        
        
      
     sed => '/bin/sed', # location of the sed binary 
      
        
        
        
      
     iptables => '/sbin/iptables', # Location of iptables binary - only for Linux 
      
        
        
        
      
     pfctl => '/sbin/pfctl', # Location of pfctl binary - only for BSD 
      
        
        
        
      
     whitelist => [qw{ 
      
        
        
        
      
     127.0.0.1/32 
      
        
        
        
      
     }], # whitelist - list of IPs that will never be blocked - IPs must be specified in the form ad$ 
      
        
        
        
      
     }; 
      
        
        
        
      
     
      
        
        
        
      
     #leave 1; here! 
      
        
        
        
      
     1; 
      
        
        
        
      
    
      
      このリストでは、強調表示された行に注意する必要があります。 1つ目は1つのアドレスから入力する最大試行回数、2つ目は3行目に指定された秒単位の時間が経過した後に禁止IPのロックを解除する必要があるかどうかです。 4番目-ハッキングの試みをメールで通知するかどうか。
これで、サーバーを再起動して、何が起こったかをテストできます。
最も簡単な監視
アクティブなセッションを監視するのに便利なように、「膝の上に」書かれたスクリプトを使用できます。 それを作成して、シンボリックリンクを設定して簡単に起動し、もちろんチェックしてみましょう:
以下を開始します。
nano /root-scripts/clients
      
      スクリプト:
#!/usr/bin/php 
      
        
        
        
      
     <? 
      
        
        
        
      
     function time_since($original) { 
      
        
        
        
      
     $chunks = array( 
      
        
        
        
      
     array(60 * 60 * 24 , 'D '), 
      
        
        
        
      
     array(60 * 60 , 'h:'), 
      
        
        
        
      
     array(60 , 'min'), 
      
        
        
        
      
     ); 
      
        
        
        
      
     $today = time(); 
      
        
        
        
      
     $since = $today - $original; 
      
        
        
        
      
     for ($i = 0, $j = count($chunks); $i < $j; $i++) { 
      
        
        
        
      
     $seconds = $chunks[$i][0]; 
      
        
        
        
      
     $name = $chunks[$i][1]; 
      
        
        
        
      
     if (($count = floor($since / $seconds)) != 0) { 
      
        
        
        
      
     break; 
      
        
        
        
      
     } 
      
        
        
        
      
     } 
      
        
        
        
      
     $print = "$count{$name}"; 
      
        
        
        
      
     if ($i + 1 < $j) { 
      
        
        
        
      
     $seconds2 = $chunks[$i + 1][0]; 
      
        
        
        
      
     $name2 = $chunks[$i + 1][1]; 
      
        
        
        
      
     if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) { 
      
        
        
        
      
     $print .= "$count2{$name2}"; 
      
        
        
        
      
     } 
      
        
        
        
      
     } 
      
        
        
        
      
     return $print; 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     function execShellCmdRaw($cmd) { 
      
        
        
        
      
     ob_start(); 
      
        
        
        
      
     passthru($cmd); 
      
        
        
        
      
     $buffer = ob_get_contents(); 
      
        
        
        
      
     ob_end_clean(); 
      
        
        
        
      
     return $buffer; 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     function rawToArray($buffer) { 
      
        
        
        
      
     return empty($buffer)?array():preg_split('/[\r\n]+/', $buffer, -1, PREG_SPLIT_NO_EMPTY); 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     function execShellCmd($cmd) { 
      
        
        
        
      
     return rawToArray(execShellCmdRaw($cmd)); 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     function getNATSources() { 
      
        
        
        
      
     $nat = execShellCmd('iptables -t nat -L | grep MASQUERADE'); 
      
        
        
        
      
     $nats = array(); 
      
        
        
        
      
     foreach ($nat as $s) { 
      
        
        
        
      
     $pos_start = strpos($s, '--') + 2; 
      
        
        
        
      
     $pos_end = strpos($s, 'anywhere'); 
      
        
        
        
      
     $n = trim(substr($s, $pos_start, $pos_end - $pos_start)); 
      
        
        
        
      
     $nats[$n] = $n; 
      
        
        
        
      
     } 
      
        
        
        
      
     return $nats; 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     function getTunnelMacAddr($pid) { 
      
        
        
        
      
     $pppdc = execShellCmd('ps -p '.$pid.' -f | grep pppd'); 
      
        
        
        
      
     $pppdc = $pppdc[0]; 
      
        
        
        
      
     $pos_start = strpos($pppdc, '-e ') + 3; 
      
        
        
        
      
     $pos_end = strpos($pppdc, '-S \'\''); 
      
        
        
        
      
     return trim(substr($pppdc, $pos_start, $pos_end - $pos_start)); 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     function getPPPTunnels() { 
      
        
        
        
      
     $ifc = execShellCmd('ifconfig -a'); 
      
        
        
        
      
     $tunnels = array(); 
      
        
        
        
      
     $nat = getNATSources(); 
      
        
        
        
      
     foreach ($ifc as $i => $s) { 
      
        
        
        
      
     if (substr($s, 0, 3) == 'ppp') { 
      
        
        
        
      
     $ppp = array(); 
      
        
        
        
      
     $ppp['interface'] = substr($s, 0, 4); 
      
        
        
        
      
     $ppp['framed_ip'] = trim(substr($ifc[$i+1], strpos($ifc[$i+1], 'PtP:') + 6, 12)); 
      
        
        
        
      
     $RXpos_start = strpos($ifc[$i+6], '(') + 1; 
      
        
        
        
      
     $RXpos_end = strpos($ifc[$i+6], ')'); 
      
        
        
        
      
     $ppp['tx'] = substr($ifc[$i+6], $RXpos_start, $RXpos_end - $RXpos_start); //TX(user) = RX(server) 
      
        
        
        
      
     $tx_sub = substr($ifc[$i+6], $RXpos_end + 1); 
      
        
        
        
      
     $TXpos_start = strpos($tx_sub, '(') + 1; 
      
        
        
        
      
     $TXpos_end = strpos($tx_sub, ')'); 
      
        
        
        
      
     $ppp['rx'] = substr($tx_sub, $TXpos_start, $TXpos_end - $TXpos_start); 
      
        
        
        
      
     $ppp['nat'] = array_key_exists($ppp['framed_ip'], $nat)?'on':'off'; 
      
        
        
        
      
     $pidf = '/var/run/'.$ppp['interface'].'.pid'; 
      
        
        
        
      
     if (file_exists($pidf)) { 
      
        
        
        
      
     $ppp['uptime'] = time_since(filemtime($pidf)); 
      
        
        
        
      
     $ppp['pid'] = trim(file_get_contents($pidf)); 
      
        
        
        
      
     $ppp['mac_addr'] = getTunnelMacAddr($ppp['pid']); 
      
        
        
        
      
     $ppp['username'] = 'detectedusername'; 
      
        
        
        
      
     $tunnels[] = $ppp; 
      
        
        
        
      
     } 
      
        
        
        
      
     } 
      
        
        
        
      
     } 
      
        
        
        
      
     return $tunnels; 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     function clientTable($tunnels) { 
      
        
        
        
      
     printf("\n"); 
      
        
        
        
      
     printf(" %15s | ","IP Address"); 
      
        
        
        
      
     printf("%20s | ","MAC Address "); 
      
        
        
        
      
     printf("%3s | ","NAT"); 
      
        
        
        
      
     printf("%16s | ","User name "); 
      
        
        
        
      
     printf("%9s | ","TX (up)"); 
      
        
        
        
      
     printf("%9s | ","RX (down)"); 
      
        
        
        
      
     printf("%11s","Uptime "); 
      
        
        
        
      
     printf("\n "); 
      
        
        
        
      
     for ($i = 0; $i < 101; $i++) printf("-"); 
      
        
        
        
      
     printf("\n"); 
      
        
        
        
      
     foreach($tunnels as $tun) { 
      
        
        
        
      
     printf(" %15s | ",$tun['framed_ip']); 
      
        
        
        
      
     printf("%20s | ",$tun['mac_addr']); 
      
        
        
        
      
     printf("%3s | ",$tun['nat']); 
      
        
        
        
      
     printf("%16s | ",$tun['username']); 
      
        
        
        
      
     printf("%9s | ",$tun['tx']); 
      
        
        
        
      
     printf("%9s | ",$tun['rx']); 
      
        
        
        
      
     printf("%11s",$tun['uptime']); 
      
        
        
        
      
     printf("\n"); 
      
        
        
        
      
     } 
      
        
        
        
      
     printf("\n"); 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     function addRadParams(&$tunnels = NULL) { 
      
        
        
        
      
     $radusers = rawToArray(file_get_contents('/etc/freeradius/users')); 
      
        
        
        
      
     $users = array(); 
      
        
        
        
      
     foreach ($radusers as $i => $s) { 
      
        
        
        
      
     if (strpos($s, 'Cleartext-Password') !== FALSE) { 
      
        
        
        
      
     $user = array(); 
      
        
        
        
      
     $user['username'] = trim(substr($s, 0, strpos($s, 'Cleartext-Password'))); 
      
        
        
        
      
     $si = $i + 1; 
      
        
        
        
      
     while (strpos($radusers[$si], 'Framed-IP-Address') == FALSE) $si++; 
      
        
        
        
      
     $ip_raw = explode('=', $radusers[$si]); 
      
        
        
        
      
     $ip_raw = $ip_raw[1]; 
      
        
        
        
      
     $users[trim($ip_raw, ' ,')] = $user; 
      
        
        
        
      
     } 
      
        
        
        
      
     } 
      
        
        
        
      
     foreach ($tunnels as $i => $tun) { 
      
        
        
        
      
     $tunnels[$i]['username'] = $users[$tun['framed_ip']]['username']; 
      
        
        
        
      
     } 
      
        
        
        
      
     return $tunnels; 
      
        
        
        
      
     } 
      
        
        
        
      
     
      
        
        
        
      
     $t = getPPPTunnels(); 
      
        
        
        
      
     addRadParams($t); 
      
        
        
        
      
     clientTable($t); 
      
        
        
        
      
    
      
      以下を開始します。
chmod +x /root-scripts/clients 
      
        
        
        
      
     ln -s /root-scripts/clients /usr/bin/clients 
      
        
        
        
      
     clients 
      
        
        
        
      
    
      
      次のようなものが得られます。
IP Address | MAC Address | NAT | User name | TX (up) | RX (down) | Uptime 
      
        
        
        
      
     ----------------------------------------------------------------------------------------------------- 
      
        
        
        
      
     10.128.1.7 | 1:00:19:66:df:39:26 | on | room56 | 507.4 MiB | 445.5 MiB | 16h:31min 
      
        
        
        
      
     10.128.1.3 | 23:00:13:8f:70:30:03 | on | room47 | 8.2 MiB | 137.8 MiB | 1h:14min 
      
        
        
        
      
     10.128.1.5 | 3:00:a1:b0:11:74:cf | on | room50 | 19.2 MiB | 500.2 MiB | 16h:30min 
      
        
        
        
      
    
      
      以上で、サーバーを使用する準備が整いました。 私の観察によれば、1 GB DDR1と2 GHzプロセッサを備えたシンプルなシステムユニットで30ユーザーに16メガバイトのチャネルを分配するのに十分であり(もはや必要ありません)、システムに顕著な負荷は発生しません。
プロバイダーを始めて頑張ってください!