cent6.x配置主机名及静态网络

# 修改网卡名为NAME="eth0"
[root@jenkins ~]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:32:d6:05", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# 必须重启使eth0网卡名生效
[root@jenkins ~]# reboot

# 启用eth0网卡
[root@jenkins ~]# ifup eth0

# 设置IP和掩码
[root@jenkins ~]# ifconfig eth0 192.168.66.14 netmask 255.255.255.0

# 设置网关
[root@jenkins ~]# route add default gw 192.168.66.254

# 检查静态IP、掩码、网关设置,HWADDR(网卡MAC地址),UUID(网卡唯一ID)结果
[root@jenkins ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:50:56:28:0D:BD
TYPE=Ethernet
UUID=5cd00730-f5bc-4783-a160-3c5e06bfa932
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.66.14
NETMASK=255.255.255.0
GATEWAY=192.168.66.254

# 修改主机名
[root@jenkins ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=jenkins

# 修改主机名
[root@jenkins ~]# cat /etc/hosts
127.0.0.1   jenkins localhost.localdomain localhost4 localhost4.localdomain4
::1         jenkins localhost.localdomain localhost6 localhost6.localdomain6

# 检查主机名
[root@jenkins ~]# hostname
jenkins

其他参考文档:

https://www.cnblogs.com/vicowong/archive/2011/04/23/2025545.html

 

# cat /etc/resolv.conf 
修改前
nameserver 218.85.157.99
nameserver 218.85.152.99
改为
nameserver 114.114.114.114
nameserver 8.8.8.8


nameserver 8.8.8.8      #GOOGLE的DNS服务器
nameserver 61.144.56.100      #指定当前城市最近的DNS服务器(各城市不一样,上网搜索)
nameserver 192.168.1.1      #指定经路由器上指定的DNS服务器



[root@localhost ~]# vim /etc/resolv.conf
// 原先的DNS
# Generated by NetworkManager
nameserver 8.8.8.8

// 修改后的DNS
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8

网关不通,不能连外网问题

https://www.centos.org/forums/viewtopic.php?t=48096

posted @ 2018-10-30 17:14  任国强  阅读(232)  评论(0编辑  收藏  举报