一.网络配置之静态IP:

树莓派的默认网络为:

haochuang@raspberrypi:~ $ vi /etc/network/interfaces
# interfaces() file used by ifup() and ifdown() # 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/
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() file used by ifup() and ifdown()

# 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= 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.                                                  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() for more information on "#include" directives: #includedir /etc/sudoers.d pi ALL=(ALL) NOPASSWD: ALL [ Read 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:
# Default-Stop:
# Required-Start: $local_fs
# Required-Stop:
# chkconfig:
# Short-Description: Start or stop the testapp App.
### END INIT INFO start(){
echo -e "\033[32m start testapp \033[0m"
cd /home/haochuang/webapp/testapp
su lifeccp -c "sh /home/haochuang/webapp/testapp/start --spring.profiles.active=test &"
} stop(){
echo -e "\033[32m stop osprey \033[0m"
pkill -f testapp app_pid=$(pgrep -f testapp)
if [ "${app_pid}" = "" ]; then
echo -e "\033[32m -=stop testapp finished=- \033[0m"
else
echo -e "\033[31m -=stop testapp failed=- \033[0m"
kill - "${app_pid}"
echo -e "\033[32m -=kill -9 testapp=- \033[0m"
fi
} case $ in
start)
start
;;
stop)
stop
;;
*)
echo -e "\033[32m Usage: $0 (start|stop) \033[0m"
;;
esac

注意上面脚本中的\033[0m,其实是在为服务控制指令加色,想了解详细,可参考后面"其他"的补充描述;

2.增加到 /etc/init.d中,并修改增加可执行权限;

chomd +x testapp

3.增加到启动项中

chkconfig add /etc/init.d/testapp

其他:

颜色特效控制:

printf("\033[1;33m Hello World. \033[0m \n");
颜色如下:
none = "\033[0m"
black = "\033[0;30m"
dark_gray = "\033[1;30m"
blue = "\033[0;34m"
light_blue = "\033[1;34m"
green = "\033[0;32m"
light_green -= "\033[1;32m"
cyan = "\033[0;36m"
light_cyan = "\033[1;36m"
red = "\033[0;31m"
light_red = "\033[1;31m"
purple = "\033[0;35m"
light_purple = "\033[1;35m"
brown = "\033[0;33m"
yellow = "\033[1;33m"
light_gray = "\033[0;37m"
white = "\033[1;37m"

字背景颜色范围: 40--49 字颜色: 30--39
40: 黑 30: 黑
41:红 31: 红
42:绿 32: 绿
43:黄 33: 黄
44:蓝 34: 蓝
45:紫 35: 紫
46:深绿 36: 深绿
47:白色 37: 白色

输出特效格式控制:

\033[0m 关闭所有属性
\033[1m 设置高亮度
\03[4m 下划线
\033[5m 闪烁
\033[7m 反显
\033[8m 消隐
\033[30m -- \033[37m 设置前景色
\033[40m -- \033[47m 设置背景色

光标位置等的格式控制:

\033[nA 光标上移n行
\03[nB 光标下移n行
\033[nC 光标右移n行
\033[nD 光标左移n行
\033[y;xH设置光标位置
\033[2J 清屏
\033[K 清除从光标到行尾的内容
\033[s 保存光标位置
\033[u 恢复光标位置
\033[?25l 隐藏光标
\33[?25h 显示光标

【树莓派】树莓派网络配置:静态IP、无线网络、服务等的更多相关文章

  1. VMware中安装CentOS7网络配置静态IP地址,常用配置和工具安装

    VMware中安装CentOS7网络配置静态IP地址,常用配置和工具安装在阿里云开源镜像地址下载镜像Index of /centos/7.2.1511/isos/x86_64/http://mirro ...

  2. VMware中对Linux虚拟机的网络配置静态IP的配置

    前言 踏出象牙塔,进入公司,由于公司的所有产品都是Linux下的,必然自己这段时间需要在自己的工作机器先学习一下.项目代码是用Source Insight进行查看的,总是Ctrl + Alt的切来切去 ...

  3. 转:VMware中CentOS配置静态IP进行网络访问(NAT方式和桥接模式)

    传送门:http://blog.csdn.net/zhangatle/article/details/77417310 其实这个博主的博客最是适合新手学习,踩过的坑让我再踩一踩,印象深刻 首先进行NA ...

  4. 1 weekend110的Linux带图形系统安装 + 网络配置 + 静态IP设置

    一.weekend110的Linux带图形系统安装 二.网络配置 明明是配置好的啊,只能说是域名出现问题了, 出现ping:unknow host www.baidu.com的问题解决 解决Ubunt ...

  5. VMware VMnet8 模式共享主机网络配置静态 IP 和 DNS

    一.简介 NAT网络模式: 1. 宿主机可以看做一个路由器,虚拟机通过宿主机的网络来访问  Internet: 2. 可以安装多台虚拟机,组成一个小型局域网,例如:搭建 hadoop 集群.分布式服务 ...

  6. CentOS 6.5网络配置静态IP地址

    打开VMvare,并进入虚拟机 2 输入用户名,按回车键,再输入密码,登录系统 3 进行网络配置前,需要确认几个事情: 1. 网络适配器模式是否为NAT模式 右键虚拟机,或者点击VMvare菜单栏中的 ...

  7. 在VMware中为CentOS配置静态ip并可访问网络-Windows下的VMware

    在VMware中为CentOS配置静态ip并可访问网络-Windows下的VMware 首先确保虚拟网卡(VMware Network Adapter VMnet8)是开启的,然后在windows的命 ...

  8. 虚拟机网络NAT模式配置静态IP

    虚拟机网络连接方式 安装好虚拟机以后,在网络连接里面可以看到多了两块网卡: 其中VMnet1是虚拟机Host-only模式的网络接口,VMnet8是NAT模式的网络接口. 虚拟机常见有三种网络连接方式 ...

  9. 在VMware中为CentOS配置静态ip并可访问网络

    在VMware中为CentOS配置静态ip并可访问网络-windows下的VMware  首先确保虚拟网卡(VMware Network Adapter VMnet8)是开启的,然后在windows的 ...

  10. CENTOS7配置静态IP后无法ping通外部网络的问题

    我今天想谈论的并不是如何配置静态IP,这样的话题已经有好多高手再谈. 我想谈的是为什么,我按照他们的教程无论如何也要发生各种问题,没办法连接外网的问题. 先给大家看我的最终版配置方案:我只修改了一个文 ...

随机推荐

  1. 解决Sublime Text 3 Package Control 问题

    我使用的环境是 Mac OS X 10.11.5. 安装Packet Control之后,尝试安装插件,出现如下问题: There are no packages available for inst ...

  2. 《UML大战需求分析》阅读笔记01

    在刚学习软件开发的课程时,首先学习了UML设计,但只是学习了基本的语法,虽然在学期通过课堂练习进行了实践,但并没有真正理解其中作用.为了进一步的理解UML的用法,我阅读了<UML大战需求分析&g ...

  3. C#中 MD5和SHA1加密代码

    Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(entity.Pwd, "MD5"); Pwd = For ...

  4. bootstrap组件学习

    转自http://v3.bootcss.com/components/ bootstrap组件学习 矢量图标的用法<span class="glyphicon glyphicon-se ...

  5. PHP->利用GD库新建图像

    1.确认php中GD库是否开启 在PHP配置文件php.ini中查找extension=php_gd2.dll,去掉前边的(分号) ';' 即可,一般php是默认开启的 2.绘画步骤 创建一个画布(画 ...

  6. phpcms v9 的表单向导功能的使用方法

    本文主要介绍phpcms v9的表单向导功能是如何使用的,并副多个案例讲解: 先介绍一下v9 的表单向导如何使用 表单向导做的很实用,生成一个表单,常用的是把它作为一个留言板,或者在招聘栏目作为一个供 ...

  7. python时间操作总结

    Unix时间戳 Unix时间戳(Unix timestamp),或称Unix时间(Unix time).POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间1970年01月 ...

  8. android如何获取到启动类的包和类路径

    ArrayList<String> list = new ArrayList<String>(); private List<ResolveInfo> mApps; ...

  9. lodash源码(2)

    1.flatten 对深层嵌套数组的抹平 _.flatten([1, [2, 3, [4]]]);* // => [1, 2, 3, [4]]** // using `isDeep`* _.fl ...

  10. PL/SQL不支持64位Oracle Client 解决办法

    解决X64操作系统PL/SQL连接报错问题 make sure you have the 32 bits oracle client installed 说明PLSQL Developer并不支持Or ...