Published Book on Amazon
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1 | |
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2 |
출판된 한글판 도서
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상) | |
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하) |
Original Book Contents
11.7 Activation and Stop of Network
While operating the system, you may need to stop and reactivate the network device as needed for various reasons, such as an error occuring or changes to the configuration. If the existing device is stopped, the network connection is disconnected, and the IP address that was previously assigned can not be used. When the connection is stopped and a new connection is made, the network connection is made according to the latest setting contents.
You can use several commands to stop and reactivate the Raspberry Pi system. Let's look at each command one by one.
11.7.1 Network Activation/Stop by "ifup" and "ifdwon" Command
You can activate or stop the network with use the "ifup" and "ifdown" commands.
The "ifup" command activates the network device and connects it to the network. Use the following format.
[Command Format]
ifup [option] [interface] |
The "ifdown" command stops the network connection. Use the following format.
[Command Format]
ifdown [option] [interface] |
[Command Overview]
■ This activates or deactivates the network.
■ User privilege -- Normal user.
[Detail Description]
■ None
[Main Option]
-h, --help | Show summary of options |
-a, --all
| If given to ifup, affect all interfaces marked auto. Interfaces are brought up in the order in which they are defined in /etc/network/interfaces. Combined with --allow, acts on all interfaces of a specified class instead. If given to ifdown, affect all defined interfaces. Interfaces are brought down in the order in which they are currently listed in the state file. Only interfaces defined in /etc/network/interfaces wil be brought down. |
[Used Example]
The following example tests the operation of stoping and again activating the wired network "eth0".
pi@raspberrypi ~ $ ifconfig |
eth0 Link encap:Ethernet HWaddr b8:27:eb:e2:c7:4b inet addr:192.168.1.202 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5863 errors:0 dropped:0 overruns:0 frame:0 TX packets:3809 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:580531 (566.9 KiB) TX bytes:1502976 (1.4 MiB)
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:1854 errors:0 dropped:0 overruns:0 frame:0 TX packets:1854 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:21760384 (20.7 MiB) TX bytes:21760384 (20.7 MiB)
wlan0 Link encap:Ethernet HWaddr 48:02:2a:87:cb:26 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:2 overruns:0 frame:0 TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:17665 (17.2 KiB) TX bytes:41927 (40.9 KiB) |
If you look at the network status with "ifconfig" before working, you can see that the IP address is given as 192.168.1.202 for "eth0", the wired network device. If you stop the device with the "ifdown" command and check the network status with the "ifconfig" command again, you can see that the IP address is not visible.
pi@raspberrypi ~ $ sudo ifdown eth0 |
Internet Systems Consortium DHCP Client 4.2.2 Copyright 2004-2011 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/b8:27:eb:e2:c7:4b Sending on LPF/eth0/b8:27:eb:e2:c7:4b Sending on Socket/fallback DHCPRELEASE on eth0 to 192.168.1.1 port 67 Reloading /etc/samba/smb.conf: smbd only. |
pi@raspberrypi ~ $ ifconfig |
eth0 Link encap:Ethernet HWaddr b8:27:eb:e2:c7:4b UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5866 errors:0 dropped:0 overruns:0 frame:0 TX packets:3810 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:580669 (567.0 KiB) TX bytes:1503330 (1.4 MiB)
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:1856 errors:0 dropped:0 overruns:0 frame:0 TX packets:1856 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:21760484 (20.7 MiB) TX bytes:21760484 (20.7 MiB)
wlan0 Link encap:Ethernet HWaddr 48:02:2a:87:cb:26 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:2 overruns:0 frame:0 TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:17665 (17.2 KiB) TX bytes:41927 (40.9 KiB) |
After you activate the network with the "ifup" command again and look at the network status, you can see that the IP address is assigned to "eth0"
pi@raspberrypi ~ $ sudo ifup eth0 |
Internet Systems Consortium DHCP Client 4.2.2 Copyright 2004-2011 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/b8:27:eb:e2:c7:4b Sending on LPF/eth0/b8:27:eb:e2:c7:4b Sending on Socket/fallback DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4 DHCPREQUEST on eth0 to 255.255.255.255 port 67 DHCPOFFER from 192.168.1.1 DHCPACK from 192.168.1.1 Reloading /etc/samba/smb.conf: smbd only. bound to 192.168.1.202 -- renewal in 3143 seconds. |
pi@raspberrypi ~ $ ifconfig |
eth0 Link encap:Ethernet HWaddr b8:27:eb:e2:c7:4b inet addr:192.168.1.202 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5881 errors:0 dropped:0 overruns:0 frame:0 TX packets:3816 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:582509 (568.8 KiB) TX bytes:1504386 (1.4 MiB)
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:1858 errors:0 dropped:0 overruns:0 frame:0 TX packets:1858 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:21760584 (20.7 MiB) TX bytes:21760584 (20.7 MiB)
wlan0 Link encap:Ethernet HWaddr 48:02:2a:87:cb:26 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:2 overruns:0 frame:0 TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:17665 (17.2 KiB) TX bytes:41927 (40.9 KiB) |