Ubuntu VM虚拟机 Bridge方式 配置静态IP
2015-04-10 11:21
309 查看
其实网上关于这个的教程已经大把了,顺手备份几个:
虚拟网络 桥接、NAT、host-only 介绍,以及桥接方式中主机的bridge protocol设置:http://blog.csdn.net/youxin2012/article/details/17231149
桥接方式:http://blog.csdn.net/yuhaibin168/article/details/7525413
NAT方式(里面顺便介绍了一下VM的虚拟网络管理工具:Virtual Network Manager) : http://www.cnblogs.com/lanxuezaipiao/p/3613497.html
然后再说说我自己看完上述教程后,遇到的仍然没有解决的问题:
本人一开始对 /etc/network/interfaces 做的修改如下:
其中在由dhcp模式改为静态ip模式时,为了备份自己做的修改,将系统默认的dhcp直接在代码行末尾注释掉了。
恩,看起来好像没什么问题,和网上教程中描述的配置是一样的。
结果通过 /etc/init.d/networking restart 重启网络服务时,ip还是无法分配到指定的静态IP。
尝试重启Ubuntu系统,结果在系统启动时报错:Starting configure network device [failed]
百思不得其解。
最后尝试用 ifdown ifup命令手动关闭重启 eth0 网络设备。
结果报错:
/etc/network/interfaces:11: too many parameters for iface line
ifdown: couldn't read interfaces file "/etc/network/interfaces"
查看一下/etc/network/interfaces 11行的内容:
真相大白。应该是行尾末端的#dhcp注释前的空格被iface读入,导致iface以为static后面还要有参数输入(猜测,未证实)。
将#dhcp移至11行上方,interfaces文件改为:
重启网络服务,妥妥的~
后记:这次bug也提醒了我,在脚本中,好的注释习惯是在目标代码行的上方添加一行注释行,而非直接在目标代码行的末尾添加注释。
===150414更新===
今天为实验室机房另一台ubuntu服务器配置静态IP。想起之前接触的一位工程师说网络服务配置后不需要重启机器,深以为然,决定试试。
但是,问题来了,在对/etc/network/interfaces 修改后,sudo /etc/init.d/networking restart 报错:
stop: Job failed while stopping
网上查了一下,原来Ubuntu14.04坑爹的停止了 对 /etc/init.d/networking restart 的支持:https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/1301015
尽管好多人在这个bug下面吐槽,要求Ubuntu提供一个更好的解决办法,但是,现在的情况是只能通过 sudo ifdown --- && sudo ifup --- 进行相应网络设备的重启。(叹气)
==== 附录更新 ====
其他觉得很有帮助的文章:
【0】http://www.linuxquestions.org/questions/linux-newbie-8/etc-network-interfaces-too-many-parameters-for-iface-line-4175491064/
个人是通过下面这段话理解了eth0的含义,以及iface命令中相关参数的意义:
iface 网络设备ID 协议族 其他选项
【1】理解Linux系统/etc/init.d目录和/etc/rc.local脚本 /article/2149437.html
【2】ubuntu静态DNS配置,重启继续生效 http://blog.sina.com.cn/s/blog_67be3b450101de45.html
虚拟网络 桥接、NAT、host-only 介绍,以及桥接方式中主机的bridge protocol设置:http://blog.csdn.net/youxin2012/article/details/17231149
桥接方式:http://blog.csdn.net/yuhaibin168/article/details/7525413
NAT方式(里面顺便介绍了一下VM的虚拟网络管理工具:Virtual Network Manager) : http://www.cnblogs.com/lanxuezaipiao/p/3613497.html
然后再说说我自己看完上述教程后,遇到的仍然没有解决的问题:
本人一开始对 /etc/network/interfaces 做的修改如下:
#The loopback network interface auto lo iface lo inet loopback #The primary network interface auto eth0 iface eth0 inet static #dhcp address 172.21.5.41 netmask 255.255.255.0 gateway 172.21.5.254
其中在由dhcp模式改为静态ip模式时,为了备份自己做的修改,将系统默认的dhcp直接在代码行末尾注释掉了。
恩,看起来好像没什么问题,和网上教程中描述的配置是一样的。
结果通过 /etc/init.d/networking restart 重启网络服务时,ip还是无法分配到指定的静态IP。
尝试重启Ubuntu系统,结果在系统启动时报错:Starting configure network device [failed]
百思不得其解。
最后尝试用 ifdown ifup命令手动关闭重启 eth0 网络设备。
结果报错:
/etc/network/interfaces:11: too many parameters for iface line
ifdown: couldn't read interfaces file "/etc/network/interfaces"
查看一下/etc/network/interfaces 11行的内容:
iface eth0 inet static #dhcp
真相大白。应该是行尾末端的#dhcp注释前的空格被iface读入,导致iface以为static后面还要有参数输入(猜测,未证实)。
将#dhcp移至11行上方,interfaces文件改为:
#The loopback network interface auto lo iface lo inet loopback #The primary network interface auto eth0
<pre name="code" class="plain">#iface eth0 inet dhcpiface eth0 inet staticaddress 172.21.5.41netmask 255.255.255.0gateway 172.21.5.254
重启网络服务,妥妥的~
后记:这次bug也提醒了我,在脚本中,好的注释习惯是在目标代码行的上方添加一行注释行,而非直接在目标代码行的末尾添加注释。
===150414更新===
今天为实验室机房另一台ubuntu服务器配置静态IP。想起之前接触的一位工程师说网络服务配置后不需要重启机器,深以为然,决定试试。
但是,问题来了,在对/etc/network/interfaces 修改后,sudo /etc/init.d/networking restart 报错:
stop: Job failed while stopping
网上查了一下,原来Ubuntu14.04坑爹的停止了 对 /etc/init.d/networking restart 的支持:https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/1301015
尽管好多人在这个bug下面吐槽,要求Ubuntu提供一个更好的解决办法,但是,现在的情况是只能通过 sudo ifdown --- && sudo ifup --- 进行相应网络设备的重启。(叹气)
==== 附录更新 ====
其他觉得很有帮助的文章:
【0】http://www.linuxquestions.org/questions/linux-newbie-8/etc-network-interfaces-too-many-parameters-for-iface-line-4175491064/
个人是通过下面这段话理解了eth0的含义,以及iface命令中相关参数的意义:
Stanzas defining logical interfaces start with a line consisting of the word "iface" followed by the name of the logical interface. In simple configurations without mapping stanzas this name should simply be the name of the physical interface to which it is to be applied. (The default mapping script is, in effect, the echo command.) The interface name is followed by the name of the address family that the interface uses. This will be "inet" for TCP/IP networking, but there is also some support for IPX networking ("ipx"), and IPv6 networking ("inet6"). Following that is the name of the method used to configure the interface. Additional options can be given on subsequent lines in the stanza. Which options are available depends on the family and method, as described below. Additional options can be made available by other Debian packages.
iface 网络设备ID 协议族 其他选项
【1】理解Linux系统/etc/init.d目录和/etc/rc.local脚本 /article/2149437.html
【2】ubuntu静态DNS配置,重启继续生效 http://blog.sina.com.cn/s/blog_67be3b450101de45.html
相关文章推荐
- Ubuntu VM虚拟机 Bridge方式 配置静态IP
- [Ubuntu网络配置]Ubuntu GNOME版网络配置中无法将默认DHCP方式修改为静态IP的解决办法
- Android判断Wifi高级设置是静态IP配置方式还是DHCP配置方式
- Linux系统配置静态IP的方式
- LTE项目stm32单片机硬件测试(原来网络dhcp动态ip方式配置成静态ip方式)
- VMware NAT方式 CentOS 6.8配置静态IP
- VMWare虚拟机下为Ubuntu 配置静态IP上网(NAT方式)
- 配置虚拟机ubuntu的ip(bridge方式)
- kvm 配置bridge 和 NAT guest 的静态 ip
- 静态IP防ARP欺骗配置
- NAT连接虚拟机和主机的通信(静态IP配置完整图解,测试通过可用)附vmware tools的安装(未完待续)--第一篇
- 配置Windows网络同时支持DHCP和静态IP
- 配置静态 IP 地址
- NAT连接虚拟机和主机的通信(静态IP配置完整图解,测试通过可用)--结束篇
- solaris 关闭dhcp配置静态ip
- VM8下ubuntu10.04下修改mac地址和配置静态ip
- spring AOP实现(Annotation方式/静态文件配置方式)
- 采用静态配置文件方式实现AOP
- 虚拟机下ubuntu配置静态IP
- Linux下配置静态IP 设置DNS和主机名