18
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ubuntu18.04のネットワーク周り設定

Last updated at Posted at 2019-02-01

#ubuntu18.04ネットワーク周り、各種調べ方および設定

ここでは'wlp2s0'というWifi用のNICを例にして調査・設定の対象にしています。

####IPアドレス。

'wlp2s0'には192.168.0.232/24のアドレスが当たってて24ビットサブネットワーク、とわかる。

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_**UP**> mtu 1500 qdisc mq state **UP** group default qlen 1000
    link/ether 5c:e0:c5:29:b0:8a brd ff:ff:ff:ff:ff:ff
    inet **192.168.0.232/24** brd 192.168.0.255 scope global dynamic noprefixroute wlp2s0
       valid_lft 85160sec preferred_lft 85160sec
    inet6 fe80::547f:8402:57cf:f325/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

ゲートウェイは192.168.0.240とわかる。

$ sudo ip route show
default via 192.168.0.1 dev wlp2s0 proto dhcp metric 600 
169.254.0.0/16 dev wlp2s0 scope link metric 1000 
**192.168.0.0/24** dev wlp2s0 proto kernel scope link src **192.168.0.240** metric 600

####DNSサーバー
以下のコマンドで192.168.0.1とわかる(最後の行)
18.04からはもう /etc/resolv.confは使ってないみたいだ。存在はするけど。

$ sudo systemd-resolve --status
Global
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      168.192.in-addr.arpa
                      17.172.in-addr.arpa
                      18.172.in-addr.arpa
                      19.172.in-addr.arpa
                      20.172.in-addr.arpa
                      21.172.in-addr.arpa
                      22.172.in-addr.arpa
                      23.172.in-addr.arpa
                      24.172.in-addr.arpa
                      25.172.in-addr.arpa
                      26.172.in-addr.arpa
                      27.172.in-addr.arpa
                      28.172.in-addr.arpa
                      29.172.in-addr.arpa
                      30.172.in-addr.arpa
                      31.172.in-addr.arpa
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

Link 2 (wlp2s0)
      Current Scopes: DNS
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: 192.168.0.1

変更方法

/etc/systemd/resolved.confというファイルのDNSの項目を編集
2つある場合はスペースで区切る。

$ sudo vi /etc/systemd/resolved.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[Resolve]
DNS=192.168.0.1 8.8.8.8
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes

####ネットワーク設定ファイル

18.04からはもう/etc/network/interfacesは使ってないみたいだ。存在はするけど。
/etc/netplan/なんちゃら.yamlというファイルになった。

デフォルト状態(デフォルトでDHCPクライアント)

$ cat /etc/netplan/01-network-manager-all.yaml

network:
  version: 2
  renderer: NetworkManager

####固定IPにしたいとき

yamlなのでインデントにタブ文字は使えない?。スペースでインデントしたほうがいいかも。

network:
    ethernets:
        <デバイス>:
            addresses:
            - <IPアドレス>
            gateway4: <デフォルトゲートウェイ>
            dhcp4: false
            nameservers:
                addresses:
                - <DNSネームサーバー>
    version: 2

例:

network:
    ethernets:
        wlp2s0:
            addresses:
            - 192.168.0.232/24
            gateway4: 192.168.0.240
            dhcp4: false
            nameservers:
                addresses:
                - 192.168.1.1
    version: 2

ネットワークマネージャを再起動して反映

$ sudo ip addr flush dev wlp2s0
$ sudo systemctl restart networking

DHCPの場合はさらに次のコマンドが必要かも(Windowsのipconfig /renewみたいなもの)

$ sudo dhclient -v wlp2s0
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlp2s0/5c:e0:c5:29:b0:8a
Sending on   LPF/wlp2s0/5c:e0:c5:29:b0:8a
Sending on   Socket/fallback
DHCPREQUEST of 192.168.0.240 on wlp2s0 to 255.255.255.255 port 67 (xid=0x47d1ff9d)
DHCPACK of 192.168.0.240 from 192.168.0.1
bound to 192.168.0.240 -- renewal in 36205 seconds.

DHCPリゾルバを止めたいとき(固定IPにした時など)

sudo kill `cat /run/dhclient.eth0.pid`
sudo rm /run/dhclient.wlp2s0.pid

##追記

####NICの状態管理

$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 5c:e0:c5:29:b0:8a brd ff:ff:ff:ff:ff:ff

#####NICのUP/DOWN

Down

$ sudo ip link set wlp2s0 down
$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DORMANT group default qlen 1000
    link/ether 5c:e0:c5:29:b0:8a brd ff:ff:ff:ff:ff:ff

UP

$ sudo ip link set wlp2s0 up
$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 5c:e0:c5:29:b0:8a brd ff:ff:ff:ff:ff:ff

リンクアップダウンをしたら、DHCPの場合次のコマンドが必要かも(Windowsのipconfig /renewみたいなもの)

$ sudo dhclient -v wlp2s0
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlp2s0/5c:e0:c5:29:b0:8a
Sending on   LPF/wlp2s0/5c:e0:c5:29:b0:8a
Sending on   Socket/fallback
DHCPREQUEST of 192.168.0.240 on wlp2s0 to 255.255.255.255 port 67 (xid=0x47d1ff9d)
DHCPACK of 192.168.0.240 from 192.168.0.1
bound to 192.168.0.240 -- renewal in 36205 seconds.

以上。

もう16.10までのやり方は忘れたほうがいいです。

18
24
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
18
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?