オフな感じ

自身の備忘録や独り言

マルチホーム環境でDHCPサービス提供インタフェースを指定する

2022-08-26 14:13:50 | Weblog

isc-dhcp-server特有かもしれないが、DHCPサービスは全てのインタフェースで動くらしい。

上位側インタフェースはプロバイダ提供のルータで稼働済みなので、ここは止めたい。

調べてみると、/etc/default/isc-dhcp-serverにインタフェース書くらしい。

デフォルトの内容はこちら

mint@mint-GK41:~$ cat /etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)

# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid

# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4=""
INTERFACESv6=""
mint@mint-GK41:~

 

DHCPサーバを書いたのがこれ。 v6は使わないつもりだけど書いた

mint@mint-GK41:~$ cat /etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)

# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid

# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="enp2s0"
INTERFACESv6="enp2s0"
mint@mint-GK41:~

 


無線APが届いた

2022-08-21 15:08:19 | Weblog

タイトルの通り、無線APが届いたので早速使ってみる。

接続は当初想定通り、既存のプロバイダ提供のルータ(無線内蔵)のLAN側に接続した。

同じPCで、既存のWifiに接続した時と今回購入のWifiに接続して速度を測った。

無線速度比較

 

ダウンロード速度は倍速となったが、アップロードはPC側の問題で頭打ち状態なのが悲しい・・・


次は強制的にProxy通るように変更する

2022-08-20 12:24:48 | Weblog

初めてやる設定だから調べながら・・・

 

http(80),https(443)の通信をProxyに向ける設定はイメージ出来たが、

Proxy側の設定も気にしながら調べているとhttpsについて結構面倒な事が分かった。

 

その内容はこちらのサイトで図解されているので省略する。

当初、Proxyの存在は隠し、徐々に速度制限かけて夜は使えなくなる(する)想定だったが、

大変そうな事と、稼働する前に夏休みが終わってしまう・・・・

 

なので、明示Proxyに方針変更(苦笑)


透過型Proxyサーバ(の前に・・・)

2022-08-11 12:53:22 | Weblog

透過型Proxyは作ったことないので、まずは普通のProxyとして設定

Proxyと言えばsquid。squidをインストールする。

mint@mint-GK41:~$ sudo apt install squid

デフォルトの設定ファイル

mint@mint-GK41:~$ grep -v -e '^\s*#' -e '^\s*$' /etc/squid/squid.conf
acl localnet src 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8             # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10          # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16         # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12          # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16         # RFC 1918 local private network (LAN)
acl localnet src fc00::/7               # RFC 4193 local private network range
acl localnet src fe80::/10              # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
include /etc/squid/conf.d/*
http_access allow localhost
http_access deny all
http_port 3128
coredump_dir /var/spool/squid
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern \/(Packages|Sources)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
refresh_pattern \/Release(|\.gpg)$ 0 0% 0 refresh-ims
refresh_pattern \/InRelease$ 0 0% 0 refresh-ims
refresh_pattern \/(Translation-.*)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
refresh_pattern .               0       20%     4320
mint@mint-GK41:~$

この設定のままパソコンにProxy設定を入れる。

パソコンのProxy設定

アクセスするとエラー

squidデフォルトではアクセスできない

あっ!

許可してないから当たり前か・・・

 

とりあえずアクセス出来るようにする。

但し、この先端末毎に制限かけ易くするために個別設定を読み込む様にする。

フォルダ構成と設定

mint@mint-GK41:/etc/squid$ pwd;find . | sort | sed '1d;s/^\.//;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/|  /g'
/etc/squid
|--conf.d
|  |--cl001.conf
|  |--cl002.conf
|  |--debian.conf
|--errorpage.css
|--squid.conf
|--squid.conf.org
mint@mint-GK41:/etc/squid$ cat conf.d/cl001.conf
# For newPC
acl cl001 src 192.168.100.1/32
http_access allow cl001
mint@mint-GK41:/etc/squid$

IPアドレスが192.168.100.1ならアクセス出来るようになった。

yahooにアクセスしたログ

mint@mint-GK41:/etc/squid$ sudo tail  /var/log/squid/access.log
1660198448.647   5619 192.168.100.1 TCP_TUNNEL_ABORTED/200 8385 CONNECT clb.yahoo.co.jp:443 - HIER_DIRECT/182.22.25.252 -
1660198448.648   1026 192.168.100.1 TCP_TUNNEL_ABORTED/200 8385 CONNECT dsb.yahoo.co.jp:443 - HIER_DIRECT/182.22.25.252 -
1660198448.648   1028 192.168.100.1 TCP_TUNNEL/200 39 CONNECT dsb.yahoo.co.jp:443 - HIER_DIRECT/182.22.25.252 -
1660198448.650   5719 192.168.100.1 TCP_TUNNEL_ABORTED/200 8385 CONNECT dsb.yahoo.co.jp:443 - HIER_DIRECT/182.22.25.252 -
1660198448.651   1028 192.168.100.1 TCP_TUNNEL_ABORTED/200 8385 CONNECT dsb.yahoo.co.jp:443 - HIER_DIRECT/182.22.25.252 -
1660198448.663   1046 192.168.100.1 TCP_TUNNEL_ABORTED/200 8385 CONNECT dsb.yahoo.co.jp:443 - HIER_DIRECT/182.22.25.252 -
1660198449.657 610613 192.168.100.1 TCP_TUNNEL/200 173358 CONNECT cdn.taboola.com:443 - HIER_DIRECT/146.75.113.44 -
1660198450.514 610977 192.168.100.1 TCP_TUNNEL/200 5747 CONNECT tempnextstat.bcovery.com:443 - HIER_DIRECT/34.117.132.248 -
1660198451.171      0 192.168.100.1 NONE/000 0 NONE error:transaction-end-before-headers - HIER_NONE/- -
1660198451.171      0 192.168.100.1 NONE/000 0 NONE error:transaction-end-before-headers - HIER_NONE/- -
mint@mint-GK41:/etc/squid$

何かエラー出てるけどブラウザの表示は問題ないので先に進む。

 


DHCPサービスを動かすた為にはインタフェースがUpが必要

2022-07-30 11:55:15 | Weblog

構築途中はPC直差しなので、起動順間違えるとサービスが起動していない・・・

気を付ければよいんだけど、本運用までにな何とかしたい。

こんなステータス

mint@mint-GK41:~$ systemctl status isc-dhcp-server
isc-dhcp-server.service - ISC DHCP IPv4 server
     Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2022-07-30 11:26:48 JST; 27min ago
       Docs: man:dhcpd(8)
    Process: 995 ExecStart=/bin/sh -ec      CONFIG_FILE=/etc/dhcp/dhcpd.conf;      if [ -f /etc/ltsp/dhcpd.conf ]; th>
   Main PID: 995 (code=exited, status=1/FAILURE)

 7月 30 11:26:48 mint-GK41 dhcpd[995]:
 7月 30 11:26:48 mint-GK41 dhcpd[995]: If you think you have received this message due to a bug rather
 7月 30 11:26:48 mint-GK41 dhcpd[995]: than a configuration issue please read the section on submitting
 7月 30 11:26:48 mint-GK41 dhcpd[995]: bugs on either our web page at www.isc.org or in the README file
 7月 30 11:26:48 mint-GK41 dhcpd[995]: before submitting a bug.  These pages explain the proper
 7月 30 11:26:48 mint-GK41 dhcpd[995]: process and the information we find helpful for debugging.
 7月 30 11:26:48 mint-GK41 dhcpd[995]:
 7月 30 11:26:48 mint-GK41 dhcpd[995]: exiting.
 7月 30 11:26:48 mint-GK41 systemd[1]: isc-dhcp-server.service: Main process exited, code=exited, status=1/FAILURE
 7月 30 11:26:48 mint-GK41 systemd[1]: isc-dhcp-server.service: Failed with result 'exit-code'.
mint@mint-GK41:~$

対応は後回しにするけど、だれか対応方法知っている人いたら教えてほしい。

 


DHCPサーバを有効にする

2022-07-24 10:06:05 | Weblog

DHCPサーバをインストール

mint@mint-GK41:~$ sudo apt install isc-dhcp-server

デフォルトの設定内容(有効行のみ)

mint@mint-GK41:~$ grep -v "#" /etc/dhcp/dhcpd.conf

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

ddns-update-style none;

適当なドメイン名と足りない情報を追加する

mint@mint-GK41:~$ cat /etc/dhcp/dhcpd.conf
option domain-name "home.net";
option domain-name-servers 192.168.1.1;
option routers 192.168.100.254;

default-lease-time 600;
max-lease-time 7200;

ddns-update-style none;

subnet 192.168.100.0 netmask 255.255.255.0 {
      range 192.168.100.1 192.168.100.99;
}
mint@mint-GK41:~$

起動する

mint@mint-GK41:~$ sudo systemctl start isc-dhcp-server

何もメッセージ出ない・・・

動作確認(windows11 home) まだ無線AP買ってないのでLANで確認

ちゃんとIPもらえて、通信OK

C:\Users\user>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : note
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : home.net

Ethernet adapter イーサネット:

   Connection-specific DNS Suffix  . : home.net
   Description . . . . . . . . . . . : Realtek PCIe GbE Family Controller
   Physical Address. . . . . . . . . : C0-18-50-70-1F-6E
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::c8d1:85b9:e47f:9230%9(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.100.1(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : 2022年7月24日 11:27:03
   Lease Expires . . . . . . . . . . : 2022年7月24日 11:37:03
   Default Gateway . . . . . . . . . : 192.168.100.254
   DHCP Server . . . . . . . . . . . : 192.168.100.254
   DHCPv6 IAID . . . . . . . . . . . : 213915728
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-2A-13-7C-82-C0-18-50-70-1F-6E
   DNS Servers . . . . . . . . . . . : 192.168.1.1
   NetBIOS over Tcpip. . . . . . . . : Enabled

自動起動する設定

mint@mint-GK41:~$ sudo systemctl enable isc-dhcp-server.service
Synchronizing state of isc-dhcp-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable isc-dhcp-server
mint@mint-GK41:~$

起動中のステータスメモ

mint@mint-GK41:~$ sudo systemctl status isc-dhcp-server
isc-dhcp-server.service - ISC DHCP IPv4 server
     Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-07-24 11:40:57 JST; 10s ago
       Docs: man:dhcpd(8)
   Main PID: 3538 (dhcpd)
      Tasks: 4 (limit: 9224)
     Memory: 4.8M
     CGroup: /system.slice/isc-dhcp-server.service
             └─3538 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf

 7月 24 11:40:57 mint-GK41 dhcpd[3538]:    in your dhcpd.conf file for the network segment
 7月 24 11:40:57 mint-GK41 dhcpd[3538]:    to which interface enp3s0 is attached. **
 7月 24 11:40:57 mint-GK41 dhcpd[3538]:
 7月 24 11:40:57 mint-GK41 dhcpd[3538]: Listening on LPF/enp2s0/84:47:09:11:8c:1d/192.168.100.0/24
 7月 24 11:40:57 mint-GK41 sh[3538]: Listening on LPF/enp2s0/84:47:09:11:8c:1d/192.168.100.0/24
 7月 24 11:40:57 mint-GK41 sh[3538]: Sending on   LPF/enp2s0/84:47:09:11:8c:1d/192.168.100.0/24
 7月 24 11:40:57 mint-GK41 sh[3538]: Sending on   Socket/fallback/fallback-net
 7月 24 11:40:57 mint-GK41 dhcpd[3538]: Sending on   LPF/enp2s0/84:47:09:11:8c:1d/192.168.100.0/24
 7月 24 11:40:57 mint-GK41 dhcpd[3538]: Sending on   Socket/fallback/fallback-net
 7月 24 11:40:57 mint-GK41 dhcpd[3538]: Server starting service.
mint@mint-GK41:~$


LinuxmintでNATさせる

2022-07-24 08:38:02 | Weblog

上位ルータに経路情報登録が出来なかったので、NATする設定を追加。

必要なパッケージを追加

mint@mint-GK41:~$ sudo apt install iptables-persistent

現時点での設定内容(何もしてない設定内容)

mint@mint-GK41:~$ cat /etc/iptables/rules.v4
# Generated by iptables-save v1.8.4 on Sun Jul 24 08:34:35 2022
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
# Completed on Sun Jul 24 08:34:35 2022
mint@mint-GK41:~$

NATするルールを追加する(enp3s0から192.168.100.0/24から出ていく)

mint@mint-GK41:~$ sudo iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o enp3s0 -j MASQUERADE
mint@mint-GK41:~$ sudo iptables-save > /etc/iptables/rules.v4
-bash: /etc/iptables/rules.v4: 許可がありません
mint@mint-GK41:~$ sudo su
root@mint-GK41:/home/mint# iptables-save > /etc/iptables/rules.v4
root@mint-GK41:/home/mint# exit
exit
mint@mint-GK41:~$ cat /etc/iptables/rules.v4
# Generated by iptables-save v1.8.4 on Sun Jul 24 08:54:56 2022
*nat
:PREROUTING ACCEPT [3:571]
:INPUT ACCEPT [3:571]
:OUTPUT ACCEPT [14:1145]
:POSTROUTING ACCEPT [14:1145]
-A POSTROUTING -s 192.168.100.0/24 -o enp3s0 -j MASQUERADE
COMMIT
# Completed on Sun Jul 24 08:54:56 2022
# Generated by iptables-save v1.8.4 on Sun Jul 24 08:54:56 2022
*filter
:INPUT ACCEPT [767:91917]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [445:37132]
COMMIT
# Completed on Sun Jul 24 08:54:56 2022
mint@mint-GK41:~$

無事Linuxの下位側に接続したPCから通信できるようになった。

(自宅インターネット環境では上りが遅い・・・)

Linux下位側からのスピードテスト(LANでの接続)

 

次は、下位側に対してDHCPサーバを有効にする。

 

 


ルーティングを有効にする

2022-07-23 15:41:43 | Weblog

2つのNICにそれぞれIPを振った。

mint@mint-GK41:~$ ifconfig
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.254  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::83b1:43fb:211f:46c1  prefixlen 64  scopeid 0x20
        ether 84:47:09:11:8c:1d  txqueuelen 1000  (イーサネット)
        RX packets 96  bytes 18878 (18.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 43  bytes 4968 (4.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.254  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::d2e1:3835:1adf:52d4  prefixlen 64  scopeid 0x20
        inet6 240d:1a:2b5:c400:7f53:3833:5e20:c385  prefixlen 64  scopeid 0x0
        ether 84:47:09:11:8c:1e  txqueuelen 1000  (イーサネット)
        RX packets 20152  bytes 5035200 (5.0 MB)
        RX errors 0  dropped 6  overruns 0  frame 0
        TX packets 3603  bytes 332862 (332.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

以後省略

このままだと通信でいる足が2本有るだけ、ルーティング情報はこんな感じ。

mint@mint-GK41:~$ netstat -rn
カーネルIP経路テーブル
受信先サイト  ゲートウェイ  ネットマスク フラグ MSS Window irtt インタフェース
0.0.0.0             192.168.1.1      0.0.0.0             UG       0      0            0     enp3s0
169.254.0.0     0.0.0.0              255.255.0.0     U         0      0             0     enp3s0
192.168.1.0     0.0.0.0             255.255.255.0  U         0      0             0     enp3s0
192.168.100.0 0.0.0.0             255.255.255.0  U         0      0             0     enp2s0
mint@mint-GK41:~

中継できるように変更する。

mint@mint-GK41:~$ sudo vi sysctl.conf

~ 抜粋 ~

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

~ 抜粋 ~

説明書きの通り、コメントを外して中継を有効にする。

再起動して、中継されるか確認する。

 

中継できるようにはなったが、上位側ルータに経路情報を登録する機能がない・・・

なので、NATさせる。

 


完成予想図をきれいにかいてみた

2022-07-23 13:05:05 | Weblog
ブログの書き始めの図が手書きで汚かったのできれいにしてみた。

この先の作業内容も・・・
 GUI接続          ←やりかけたけど必須で無いのでスキップする
 ルーティング(要らないかも)
 DHCPサーバ(基本)
 透過型Proxyサーバ
 Firewall設定(80,443をProxyに向ける)
 通信量実測
 帯域制限


GUIでもリモート接続出来るようにする

2022-07-20 23:19:44 | Weblog
GUIでの接続も必要になると思うので、有効にしてみる。
こちらのサイトを参考に進める。
設定すべき内容が良くわからないので設定はまだ。


mint@mint-GK41:~$ sudo apt install -y xrdp tigervnc-standalone-server
[sudo] mint のパスワード:

mint@mint-GK41:~$ sudo systemctl enable xrdp
Synchronizing state of xrdp.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable xrdp
mint@mint-GK41:~$ cd /etc/xrdp/
mint@mint-GK41:/etc/xrdp$ ls
cert.pem km-00000410.ini km-00000807.ini pulse
key.pem km-00000411.ini km-00000809.ini reconnectwm.sh
km-00000406.ini km-00000412.ini km-0000080a.ini rsakeys.ini
km-00000407.ini km-00000414.ini km-0000080c.ini sesman.ini
km-00000409.ini km-00000415.ini km-00000813.ini startwm.sh
km-0000040a.ini km-00000416.ini km-00000816.ini xrdp.ini
km-0000040b.ini km-00000419.ini km-0000100c.ini xrdp_keyboard.ini
km-0000040c.ini km-0000041d.ini km-00010409.ini
mint@mint-GK41:/etc/xrdp$ sudo cp xrdp.ini xrdp.ini.org

ここまでやってRDPしてみる。
ログイン情報の要求は来たが、ログインはできず・・・・
ちゃんと設定していないのが原因か。またはログイン情報の入力に問題あるのか・・・・