LoginSignup
3
3

More than 3 years have passed since last update.

CentOS7で各種ネットワークサービスを基本設定したメモ(dhcp/radius/proxy/tftp/syslog)

Last updated at Posted at 2019-01-01

はじめに

このエントリは某ページの焼き直し&集約です。
記載に古い記述などあるかもしれませんが、ご容赦ください。

対象機器および環境

検証環境

  • CentOS7(7.6.1810)
  • Ciscoルータ

ネットワーク情報

項目
サーバFQDN VMnetserv01.prosper2.net
サーバアドレス 10.254.10.251

このエントリを読むとできること

  • CentOS7を
  • dhcpサーバ 兼
  • radiusサーバ 兼
  • proxyサーバ 兼
  • tftpサーバ 兼
  • syslogサーバ

として、構築できるはず。

実装

CentOS

インストール後の作業は、さくらVPS初期設定と同じ


DHCPサーバ

10.1.12.0/24 と 10.1.22.0/24 に対して、サービス提供するようにセットアップする。

以下の情報をDHCPオプションとして配布します。

項目
DNSサーバ 10.254.10.231
ドメインサフィックス prosper2.net
DHCP割り当て範囲 10.1.12.1-230/24
DHCP割り当て範囲 10.1.22.1-230/24
デフォルトゲートウェイ 各NWアドレス末尾

パッケージインストール

# yum install dhcp
(省略)

# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)

コンフィグ修正

サンプルコンフィグは /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example を参照する。

# vi /etc/dhcp/dhcpd.conf
-----8<-----snip-----8<-----
option domain-name "prosper2.net";
option domain-name-servers 10.254.10.231;

default-lease-time 3600;
max-lease-time 7200;

log-facility local7;

#  自サブネットを記載しておかないとエラーでる
subnet 10.254.10.0 netmask 255.255.255.0 {
}

# HeadQuarter 1F Wired
subnet 10.1.12.0 netmask 255.255.255.0 {
  range 10.1.12.1 10.1.12.230;
  option subnet-mask 255.255.255.0;
  option routers 10.1.12.254;
}

# HeadQuarter 2F Wired
subnet 10.1.22.0 netmask 255.255.255.0 {
  range 10.1.22.1 10.1.22.230;
  option subnet-mask 255.255.255.0;
  option routers 10.1.22.254;
}
-----8<-----snip-----8<-----

サービス起動

FWの許可設定

# firewall-cmd --add-service=dhcp --zone=public --permanent
# firewall-cmd --reload

デーモン設定

# systemctl enable dhcpd
# systemctl start dhcpd
# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 火 2019-01-01 09:00:35 JST; 14h ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 10343 (dhcpd)
   Status: "Dispatching packets..."
   CGroup: /system.slice/dhcpd.service
           mq10343 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

 1月 01 22:42:13 VMnetserv01.prosper2.net dhcpd[10343]: DHCPREQUEST for 10.1.29.1 from 40:e2:30:af:55:79 (ICS) via ens192
 1月 01 22:42:13 VMnetserv01.prosper2.net dhcpd[10343]: DHCPACK on 10.1.29.1 to 40:e2:30:af:55:79 (ICS) via ens192

Ciscoルータでの設定

Rhq01#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Rhq01(config)#inter vlan 2012
Rhq01(config-if)#ip helper-address 10.254.10.251
Rhq01(config-if)#end
Rhq01#
Rhq01#sh run inter vlan 2012
Building configuration...

Current configuration : 136 bytes
!
interface Vlan2012
 description ### HQ_1F_WiredDevice ###
 ip address 10.1.12.254 255.255.255.0
 ip helper-address 10.254.10.251
end

動作検証

# tail /var/lib/dhcpd/dhcpd.lease

lease 10.1.12.2 {
  starts 3 2018/12/19 12:59:38;
  ends 3 2018/12/19 13:59:38;
  tstp 3 2018/12/19 13:59:38;
  cltt 3 2018/12/19 12:59:38;
  binding state free;
  hardware ethernet 5c:26:0a:2d:95:59;
  uid "\001\\&\012-\225Y";
}

raidusサーバ

10.0.0.0/8 に対して、特定ユーザ&パスワードで認証可能なように構成する。

項目
NASアドレス 10.0.0.0/8
Radiusシークレット RADIUS_SECRET
PAPアカウント foo/bar
PAPアカウント hoge/fuga

※NAS(Network Access Server)は、認証要求を出すホストのこと。(802.1X認証ならオーセンティケータ)
※PAP(Password Authentication Protocol)は、パスワードによる認証のこと。

パッケージインストール

# yum install freeradius freeradius-utils
(省略)

# systemctl status radiusd
● radiusd.service - FreeRADIUS high performance RADIUS server.
   Loaded: loaded (/usr/lib/systemd/system/radiusd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
#

コンフィグ修正

サービスそのものの設定

# vi /etc/raddb/radiusd.conf
-----8<-----snip-----8<-----
log{
    #auth = no
    auth = yes
   }
-----8<-----snip-----8<-----

NASの設定

# mv /etc/raddb/client.conf /etc/raddb/client.conf.bak
# vi /etc/raddb/client.conf
-----8<-----snip-----8<-----
client radius_clients {
        ipaddr  = 10.0.0.0
        netmask = 8
        secret  = RADIUS_SECRET
}
-----8<-----snip-----8<-----

認証ユーザの設定

# cd /etc/raddb/mods-config/files
# mv authorize authorize.orig
# vi authorize
-----8<-----snip-----8<-----
$INCLUDE /etc/raddb/mods-config/files/userlist/users.login
-----8<-----snip-----8<-----

# mkdir userlist
# vi userlist/users.login
-----8<-----snip-----8<-----
foo    Auth-Type := PAP    , Cleartext-Password := "bar"
hoge   Auth-Type := PAP    , MD5-Password := "c32ec965db3295bad074d2afa907b1c3" 
-----8<-----snip-----8<-----

MD5パスワードを利用する場合は、opensslのMD5ハッシュ値を利用する。

# echo -n fuga | openssl md5
(stdin)= c32ec965db3295bad074d2afa907b1c3

サービス起動

FWの許可設定

# firewall-cmd --add-service=radius --zone=public --permanent
# firewall-cmd --reload

デーモン設定

# systemctl enable radiusd
# systemctl start  radiusd
# systemctl status radiusd
● radiusd.service - FreeRADIUS high performance RADIUS server.
   Loaded: loaded (/usr/lib/systemd/system/radiusd.service; enabled; vendor preset: disabled)
   Active: active (running) since 水 2019-01-02 00:03:13 JST; 5s ago
  Process: 25117 ExecStart=/usr/sbin/radiusd -d /etc/raddb (code=exited, status=0/SUCCESS)
  Process: 25113 ExecStartPre=/usr/sbin/radiusd -C (code=exited, status=0/SUCCESS)
  Process: 25112 ExecStartPre=/bin/chown -R radiusd.radiusd /var/run/radiusd (code=exited, status=0/SUCCESS)
 Main PID: 25121 (radiusd)
   CGroup: /system.slice/radiusd.service
           mq25121 /usr/sbin/radiusd -d /etc/raddb

 1月 02 00:03:12 VMnetserv01.prosper2.net systemd[1]: Starting FreeRADIUS high performance RADIUS server....
 1月 02 00:03:13 VMnetserv01.prosper2.net systemd[1]: Started FreeRADIUS high performance RADIUS server..

動作検証

成功の場合

# radtest hoge fuga 10.254.10.251 123 RADIUS_SECRET
Sent Access-Request Id 26 from 0.0.0.0:40128 to 10.254.10.251:1812 length 74
        User-Name = "hoge"
        User-Password = "fuga"
        NAS-IP-Address = 10.254.10.251
        NAS-Port = 123
        Message-Authenticator = 0x00
        Cleartext-Password = "fuga"
Received Access-Accept Id 26 from 10.254.10.251:1812 to 0.0.0.0:0 length 20

失敗の場合

# radtest hoge fugu 10.254.10.251 123 RADIUS_SECRET
Sent Access-Request Id 83 from 0.0.0.0:33435 to 10.254.10.251:1812 length 74
        User-Name = "hoge"
        User-Password = "fugu"
        NAS-IP-Address = 10.254.10.251
        NAS-Port = 123
        Message-Authenticator = 0x00
        Cleartext-Password = "fugu"
Received Access-Reject Id 83 from 10.254.10.251:1812 to 0.0.0.0:0 length 20
(0) -: Expected Access-Accept got Access-Reject

proxyサーバ

10.0.0.0/8 に対して、認証無しでキャッシュサーバとして利用できるように構成する。

項目
proxyポート 8080

パッケージインストール

# yum install squid
(省略)

# systemctl status squid
● squid.service - Squid caching proxy
   Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

コンフィグ修正

# vi /etc/squid/squid.conf
-----8<-----snip-----8<-----
# Squid normally listens to port 3128
#http_port 3128
http_port 8080
-----8<-----snip-----8<-----

サービス起動

FWの許可設定

# firewall-cmd --add-port=8080/tcp --zone=public --permanent
# firewall-cmd --reload

デーモン設定

# systemctl enable squid
# systemctl start  squid
# systemctl status squid
● squid.service - Squid caching proxy
   Loaded: loaded (/usr/lib/systemd/system/squid.service; enabled; vendor preset: disabled)
   Active: active (running) since 水 2019-01-02 00:20:59 JST; 5s ago
  Process: 25205 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (code=exited, status=0/SUCCESS)
  Process: 25200 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)
 Main PID: 25208 (squid)
   CGroup: /system.slice/squid.service
           tq25208 /usr/sbin/squid -f /etc/squid/squid.conf
           tq25211 (squid-1) -f /etc/squid/squid.conf
           mq25212 (logfile-daemon) /var/log/squid/access.log

 1月 02 00:20:54 VMnetserv01.prosper2.net systemd[1]: Starting Squid caching proxy...
 1月 02 00:20:59 VMnetserv01.prosper2.net systemd[1]: Started Squid caching proxy.
 1月 02 00:20:59 VMnetserv01.prosper2.net squid[25208]: Squid Parent: will start 1 kids
 1月 02 00:20:59 VMnetserv01.prosper2.net squid[25208]: Squid Parent: (squid-1) process 25211 started

動作検証

wgetでプロキシ設定有無で「診断くん」の出力がプロキシを経由していることを確認することで動作検証とする。

普通に「診断くん」のページをwgetすると

$ wget http://taruo.net/e/ -nv -O no_proxy_conn
2019-01-02 00:32:30 URL:http://taruo.net/e/ [3427/3427] -> "no_proxy_conn" [1]
$ grep prosper2 no_proxy_conn
ダイレクトに接続しているようだ。

環境変数のhttp_proxyを設定して「診断くん」のページをwgetすると

$ env | grep proxy
$ export http_proxy=http://10.254.10.251:8080/
$ wget http://taruo.net/e/ -nv -O proxy_conn
2019-01-02 00:33:43 URL:http://taruo.net/e/ [4044/4044] -> "proxy_conn" [1]
$ grep prosper2 proxy_conn
 <TR><TD>HTTP_VIA <a href="/e/index.cgi?h=HTTP_VIA">?</a></TD><TD><font color="yellow"><b><tt>1.1 VMnetserv01.prosper2.net (squid/3.5.20)</tt></b></font></TD></TR>
Proxyを経由しているようだ。

tftpサーバ

スタントアロンでうまくいかなかったので、xinetd経由での起動にします。

パッケージインストール

# yum install tftp tftp-server xinetd

コンフィグ修正

# chmod 777 /var/lib/tftpboot
# vi /etc/xinetd.d/tftp
-----8<-----snip-----8<-----
service tftp
{
        #server_args             = -s /var/lib/tftpboot
        server_args             = -u root -c -s /var/lib/tftpboot
        #disable                 = yes
        disable                 = no
}
-----8<-----snip-----8<-----

サービス起動

FWの許可設定

# firewall-cmd --add-service=tftp --zone=public --permanent
# firewall-cmd --reload

デーモン設定
(2019.1.20追記) xinetdをインストールしただけでは、xinetdが起動していなかったので追加。

# systemctl enable xinetd
# systemctl start  xinetd
# systemctl status xinetd
● xinetd.service - Xinetd A Powerful Replacement For Inetd
   Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled; vendor preset: enabled)
   Active: active (running) since 日 2019-01-20 14:44:15 JST; 3s ago
  Process: 28872 ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 28873 (xinetd)
   CGroup: /system.slice/xinetd.service
           mq28873 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid

 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: removing discard
 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: removing discard
 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: removing echo
 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: removing echo
 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: removing tcpmux
 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: removing time
 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: removing time
 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: xinetd Version 2.3.15 started with libwrap loadavg labeled-networking options compiled in.
 1月 20 14:44:15 VMinfraserv07.prosper2.net xinetd[28873]: Started working: 1 available service
 1月 20 14:44:15 VMinfraserv07.prosper2.net systemd[1]: Started Xinetd A Powerful Replacement For Inetd.

動作検証

CiscoルータからコンフィグファイルをTFTPでputし、linuxでそのファイルをgetしてみる。

Ciscoルータからput

$ ssh rdc01
Password:
Rdc01>en
Password:
Rdc01#copy start tftp://10.254.10.251/
Address or name of remote host [10.254.10.251]?
Destination filename [rdc01-confg]?
!!
7014 bytes copied in 0.304 secs (23072 bytes/sec)

linuxサーバでget

$ tftp 10.254.10.251 -c get rdc01-confg
$ head rdc01-confg

!
! Last configuration change at 17:07:52 JST Sun Dec 16 2018 by nteam
! NVRAM config last updated at 10:07:16 JST Sat Dec 29 2018 by nteam
!
version 15.5
service timestamps debug datetime localtime
service timestamps log datetime localtime
service password-encryption
!
$

syslogサーバ

標準動作してるrsyslogdの代わりにsyslog-ngを利用する。
syslog-ngはEPELからダウンロードしてくる。

パッケージインストール

# yum install epel-release
# yum install syslog-ng

ログファイル配置場所

# mkdir /var/log/routers

コンフィグ修正

/etc/syslog-ng/conf.d/routers.conf
-----8<-----snip-----8<-----
source s_net { udp(); };
destination d_routers { file("/var/log/routers/routers.log" perm(0644) ); };
log { source(s_net); destination(d_routers); };
-----8<-----snip-----8<-----

logrotateの設定

/etc/logrotate.d/routers
/var/log/routers/routers.log {
        daily
        rotate 40
        compress
        missingok
        notifempty
        postrotate
          /bin/systemctl restart syslog-ng
        endscript
}

サービス起動

FWの許可設定

# firewall-cmd --add-service=syslog --zone=public --permanent
# firewall-cmd --reload

デーモン設定

# systemctl enable syslog-ng
# systemctl start  syslog-ng
# systemctl status syslog-ng
● syslog-ng.service - System Logger Daemon
   Loaded: loaded (/usr/lib/systemd/system/syslog-ng.service; enabled; vendor preset: enabled)
   Active: active (running) since 水 2019-01-02 01:53:49 JST; 6s ago
     Docs: man:syslog-ng(8)
 Main PID: 6621 (syslog-ng)
   CGroup: /system.slice/syslog-ng.service
           mq6621 /usr/sbin/syslog-ng -F -p /var/run/syslogd.pid

 1月 02 01:53:49 VMnetserv01.prosper2.net systemd[1]: Starting System Logger Daemon...
 1月 02 01:53:49 VMnetserv01.prosper2.net systemd[1]: Started System Logger Daemon.
#

Ciscoルータでの設定

Rdc01#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Rdc01(config)#logging 10.254.10.251
Rdc01(config)#logging source loopback 0
Rdc01(config)#end
Rdc01#copy run start
Destination filename [startup-config]?
Building configuration...
[OK]
Rdc01#

動作検証

# tail /var/log/routers/routers.log
Jan  2 02:04:08 10.101.0.1 : %SEC-6-IPACCESSLOGP: list FW01 denied tcp 176.119.4.9(41399) -> 192.168.200.254(27367), 1 packet
Jan  2 02:04:52 10.1.0.1 : %SEC-6-IPACCESSLOGP: list FW01 denied tcp 176.119.4.35(55947) -> 192.168.100.254(31232), 1 packet
(じゃんじゃか出る出る)

おわりに

感想

いつもやり方を忘れるので、自己中備忘録です。
基本的なサーバの構築は、プログラムでもコードでもないんだけど、qiitaに投稿してていいのかな。。。

出典

特にありません

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3