最近在搭建一个hadoop集群,需要将从各个节点的IP地址设置成静态IP,按理说这也是没什么难度的事,最多百度一下就能解决问题。
然而,悲催的是,我在却这里踩了一个大坑,陆陆续续折腾了一个星期才解决好这个问题。
网上的各种方法很多,但仅适用于特定的ubuntu版本。我一开始装的是最新的ubuntu-18,这个版本因为刚出来,关于怎么修改静态IP的资料几乎没有。无奈之下只好重装系统,选了ubuntu-16.4.0版本,原因无他,这个版本使用较为广泛,网上查找各种资料相比之下更为方便。这里必须吐槽的是,ubuntu改版变化太大了,系统的连续性太差,每次版本更新,大量功能的配置方法都会改变,真是让人抓狂,特别是对我这种Linux小白来说更是致命。
这次的教训是以后装任何开源软件,一律排除近三年发布的版本。新版软件由于用户基数太少,遇到问题时,很难在网上找到相应的解决办法,这一次我不但被Ubuntu坑了,也被jdk坑了一把(装了最新的jdk-2.0),在hadoop中频频跳出警告,原因是新版jdk与hadoop适配的问题。
废话不多说,以下是ubuntu-16.4.0-server静态IP的具体方法。
liang@server02:~$ vim /etc/network/interfaces
打开内容如下:
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-21-generic i686)
* Documentation: https://help.ubuntu.com/
Last login: Thu Mar 5 04:42:50 2020
liang@server02:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens33
iface ens33 inet dhcp
修改如下:
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-21-generic i686)
* Documentation: https://help.ubuntu.com/
Last login: Thu Mar 5 04:42:50 2020
liang@server02:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens33
iface ens33 inet static
address 192.168.127.101
gateway 192.168.127.2
netmask 255.255.255.0
#dns-namewerver 119.29.29.29
最后一行dns-namewerver 119.29.29.29是域名服务器地址,这里被注释掉,经过测试,它不影响静态IP的设置,其作用我后面再讲。
按以上设置完reboot重新启动静态IP即可生效(网上很多方法说重启网卡:sudo /etc/init.d/networking restart,我亲测过,该方法无效,必须重启才行)。
输入以下命令检查配置是否生效:
liang@server02:~$ ifconfig
ens33 Link encap:Ethernet HWaddr 00:0c:29:94:59:19
inet addr:192.168.127.101 Bcast:192.168.127.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe94:5919/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:217 errors:0 dropped:0 overruns:0 frame:0
TX packets:187 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19540 (19.5 KB) TX bytes:19036 (19.0 KB)
Interrupt:19 Base address:0x2000
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:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
静态ip设置成功!
但这就完了吗?试试看能不能ping通外网:
liang@server02:~$ ping www.baidu.com
ping: unknown host www.baidu.com
绝望的时候来了,果然连不上外网!
这是怎么回事?
这里是卡了我最久的地方,网上各种各样的方法全都试了个遍,全都无效,但基本将问题定位在DNS上。它要怎么配置呢?网上的方法大都在/etc/network/interfaces配置,但经过测试并没有什么卵用。最后是通过修改 /etc/resolvconf/resolv.conf.d/base配置文件才解决问题。
这个base文件本身是个空文件,在上面加上nameserver地址即可,是不是简直不要太简单??具体如下:
liang@server02:~$ vim /etc/resolvconf/resolv.conf.d/base
search mydomain.com
nameserver 119.29.29.29
编辑好后保存退出,reboot重启系统即可联通外网。
liang@server02:~$ ping www.baidu.com
PING www.a.shifen.com (163.177.151.110) 56(84) bytes of data.
64 bytes from 163.177.151.110: icmp_seq=1 ttl=128 time=12.5 ms
64 bytes from 163.177.151.110: icmp_seq=2 ttl=128 time=13.2 ms
64 bytes from 163.177.151.110: icmp_seq=3 ttl=128 time=13.9 ms
64 bytes from 163.177.151.110: icmp_seq=4 ttl=128 time=13.7 ms
64 bytes from 163.177.151.110: icmp_seq=5 ttl=128 time=13.5 ms
完美!
网友评论