一.网络配置之静态IP:
树莓派的默认网络为:
haochuang@raspberrypi:~ $ vi /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d auto lo iface lo inet loopback iface eth0 inet manual allow-hotplug wlan0 iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf allow-hotplug wlan1 iface wlan1 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
这个只要插上网线,即可自动获取到dhcp地址;
但如果需要设置为静态IP,则需要简单进行设置一下,如下操作:
haochuang@raspberrypi:~ $ vi /etc/dhcpcd.conf ...... nohook lookup-hostname interface eth0 static ip_address=192.168.21.103/24 static routers=192.168.21.1 static domain_name_servers=61.134.1.4 218.30.19.40
设置完成之后,重启网络
haochuang@raspberrypi:~ $ sudo /etc/init.d/networking restart
二.配置无线网络:
cat /etc/network/interfaces
auto lo iface lo inet loopback iface eth0 inet dhcp #allow-hotplug wlan0 #iface wlan0 inet manual #wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf #iface default inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "neu" wpa-psk "lucifer_chn"
或者
# interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d auto lo iface lo inet loopback #iface eth0 inet manual iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 #iface wlan0 inet manual #iface wlan0 inet dhcp # wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf iface wlan0 inet static wpa-ssid "Chinanet" wpa-psk "CTshi555666" address 172.27.35.20 netmask 255.255.0.0 gateway 172.27.35.1 allow-hotplug wlan1 iface wlan1 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
检查 /etc/wpa_supplicant/wpa_supplicant.conf 文件:
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="Chinanet" psk="PWD-CTshi555666-passwd" }
修改之后,重启即可;
补充:
配置无线动态IP:
auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "name" wpa-psk "passwd"
配置无线静态IP:
auto wlan0 allow-hotplug wlan0 iface wlan0 inet static wpa-ssid "name" wpa-psk "passwd" address 192.168.11.80 netmask 255.255.255.0 gateway 192.168.11.1
三.增加用户的sudo权限:
为普通用户增加sudo权限的方法,同其他一样,需要修改visudo文件,如下;
haochuang@raspberrypi:~ $ sudo visudo
GNU nano 2.2.6 File: /etc/sudoers.tmp # # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL haochuang ALL=(ALL:ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d pi ALL=(ALL) NOPASSWD: ALL [ Read 30 lines ] ^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos ^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text ^T To Spell
增加其中标红的一行,并Ctrl+X,Yes保存退出;
三.增加自动启动服务:
1.编写自动启动脚本;
haochuang@raspberrypi:~ $ sudo cat /etc/init.d/osprey #!/bin/sh ### BEGIN INIT INFO # Provides: osprey # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Required-Start: $local_fs # Required-Stop: # chkconfig: 12345 99 05 # Short-Description: Start or stop the testapp App. ### END INIT INFO start(){ echo -e "