【Linux杂记】Linux配置静态IP地址,修改主机名、host

博主使用的系统是:乌班图16.04

1、设置静态IP方法如下:

  #sudo vim /etc/network/interfaces

  #修改如下部分:

  auto eth0//ipconfig命令查看网卡名,不同版本会有改动
  iface eth0 inet static
  address 192.168.0.117
  gateway 192.168.0.1 #这个地址你要确认下网关是不是这个地址
  netmask 255.255.255.0
  network 192.168.0.0
  broadcast 192.168.0.255

  因为以前是dhcp解析,所以会自动分配dns服务器地址,而一旦设置为静态ip后就没有自动获取到的dns服务器了,设置静态IP地址后,再重启后就无法解析域名。想重新设置一下DNS,有两个办法:

  •  通过/etc/network/interfaces,在它的最后增加一句:

    dns-nameservers 8.8.8.8

    8.8.8.8是Google提供的DNS服务,这里只是举一个例子,你也可以改成电信运营商的DNS。重启后DNS就生效了。

              网通:202.102.134.68   202.102.128.68

              电信:219.146.0.130    219.150.32.132

  •  通过修改:

    /etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)

    在里面插入:
    nameserver 8.8.8.8
    nameserver 8.8.4.4

    如果有多个DNS就一行一个,修改好保存,然后执行resolvconf -u再看/etc/resolv.conf,最下面就多了2行:

    nameserver 8.8.8.8
    nameserver 8.8.4.4

立即生效sudo /etc/init.d/networking restart或sudo service network-manager restart

2.修改主机名与host:

主节点主机名称:Hadoop-host,IP地址:192.168.1.200

修改/etc/host、hostname文件,注意请在host文件中一并添加hadoopnode1机器的IP地址。

192.168.1.200 Hadoop-host
//192.168.1.201 hadoopnode1
::1         localhost

vim /etc/hostname  改名为

hadoopnode1

立即生效:sudo /etc/init.d/networking restart

3、关闭防火墙 #ufw disable

ufw -status  查看状态

(其他版本好像是iptable)

 
原文地址:https://www.cnblogs.com/the-fool/p/11054139.html