mosakabe @ ウィキ
DHCPから固定IPへ変更
最終更新:
mosakabe
-
view
現在DHCPで設定されているIPアドレスを「ifconfig」コマンドを使って確認します。
$ ifconfig
eth0 Link encap:Ethernet HWaddr ca:35:ca:5a:aa:f4
inet addr:192.168.11.16 Bcast:192.168.11.255 Mask:255.255.255.0
inet6 addr: fe80::c835:caff:fe5a:aaf4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:763 errors:0 dropped:0 overruns:0 frame:0
TX packets:460 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:63764 (63.7 KB) TX bytes:45161 (45.1 KB)
Interrupt:16
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0 frame:0
TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:28 (28.0 B) TX bytes:28 (28.0 B)
192.168.11.16 が割り振られてることがわかります。
ブロードキャストアドレスが 192.168.11.255 、ネットマスクが 255.255.255.0 であることがわかります。
ここでは、 192.168.11.100 の固定IPアドレスに設定します。
ブロードキャストアドレスが 192.168.11.255 、ネットマスクが 255.255.255.0 であることがわかります。
ここでは、 192.168.11.100 の固定IPアドレスに設定します。
次に「netstat」コマンドを使ってルーティングテーブルの確認をします。
$ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 192.168.11.1 0.0.0.0 UG 0 0 0 eth0
ネットワークアドレスが 192.168.11.0、ゲートウェイが 192.168.11.1 であることがわかります。
/etc/network/interfaces を確認します。
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp
eth0が dhcp となっていることがわかります。
このファイルを以下のように修正します。
このファイルを以下のように修正します。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.11.100
netmask 255.255.255.0
network 192.168.11.0
broadcast 192.168.11.255
gateway 192.168.11.1
#iface eth0 inet dhcp
設定を反映させるため再起動します。
$ sudo /etc/init.d/networking restart * Reconfiguring network interfaces... ssh stop/waiting ssh start/running, process 2739 [ OK ]
※sshで接続していると当然接続が切られてしまうので、
$ sudo /etc/init.d/networking restart * Reconfiguring network interfaces...
で標準出力が止まってしまうと思います。
ですが、再度ログインして ifconfig で設定が反映されていることが確認できると思います。
$ ifconfig
eth0 Link encap:Ethernet HWaddr ca:35:ca:5a:aa:f4
inet addr:192.168.11.100 Bcast:192.168.11.255 Mask:255.255.255.0
inet6 addr: fe80::c835:caff:fe5a:aaf4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2020 errors:0 dropped:0 overruns:0 frame:0
TX packets:1312 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:164049 (164.0 KB) TX bytes:125891 (125.8 KB)
Interrupt:16
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0 frame:0
TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:28 (28.0 B) TX bytes:28 (28.0 B)
IPアドレスが変更されていることがわかります。
参考:
http://tobysoft.net/wiki/index.php?Ubuntu%2F%A5%A4%A5%F3%A5%B9%A5%C8%A1%BC%A5%EB%B8%E5%A4%CE%C0%DF%C4%EA
http://blog.veryposi.info/server/server-setup/ubuntu-interfaces/
http://tobysoft.net/wiki/index.php?Ubuntu%2F%A5%A4%A5%F3%A5%B9%A5%C8%A1%BC%A5%EB%B8%E5%A4%CE%C0%DF%C4%EA
http://blog.veryposi.info/server/server-setup/ubuntu-interfaces/
以下広告