CentOS 7 配置静态 ip
1. 需求场景:
在 CentOS7 上部署了一个 svn ,由于centOS7 默认是 dhcp 的,所以每过一段时间 ip 就会有变化,而 svn 要求 ip 是不能变的,不然没法同步。
网上找了篇 blog 参考: http://www.cnblogs.com/Leo_wl/p/5484136.html
2. 将/etc/sysconfig/network-scripts/ 下的网络连接文件配置为:
TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" PEERDNS="yes" PEERROUTES="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_PEERDNS="yes" IPV6_PEERROUTES="yes" IPV6_FAILURE_FATAL="no" NAME="eno16777736" UUID="440bdf0c-7e86-4586-b6b9-902a2e7b6cda" DEVICE="eno16777736" ONBOOT="yes" IPADDR="192.168.178.133" #静态 ip GATEWAY="192.168.1.1" NETMASK="255.255.255.0" DNS1="192.168.1.1" # 家里的电信路由器 ip #HWADDR="00-50-56-C0-00-01"
3. service network restart 执行网络服务重启命令,但是显示失败:
Restarting network (via systemctl): Job for network.service failed. See *systemctl status network.service* and *journalctl -xn* for details.
根据以上提示查找问题,但没有发现有价值信息
4. 百度该问题,http://tieba.baidu.com/p/3233996339 得到建议
建议一. 修改 vmware 网络连接方式,由 NET 模式(共享主机模式)改为桥接模式,
改了之后执行 service network restart 启动真的成功了.
但是,地址还是自动分配的
建议二. 复制网络连接文件, ifcfg-eno16777736 到新文件 ifcfg-eth0
root@vm-xiluhua /etc/sysconfig/network-scripts # cp ifcfg-eno16777736 ifcfg-eth0 root@vm-xiluhua /etc/sysconfig/network-scripts # service network restart Restarting network (via systemctl): [ 确定 ]
5. 再次 ip addr 查看,看到以太网卡 eno16777736 下面有两个 ip了,134 和 133
root@vm-xiluhua /etc/sysconfig/network-scripts # ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a4:5f:1e brd ff:ff:ff:ff:ff:ff inet 192.168.178.134/24 brd 192.168.178.255 scope global dynamic eno16777736 valid_lft 1798sec preferred_lft 1798sec inet 192.168.178.133/24 brd 192.168.178.255 scope global secondary eno16777736 valid_lft forever preferred_lft forever 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN link/ether 52:54:00:c4:9c:8b brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500 link/ether 52:54:00:c4:9c:8b brd ff:ff:ff:ff:ff:ff
6. ping www.baidu.com 成功
root@vm-xiluhua /etc/sysconfig/network-scripts # ping www.baidu.com PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data. 64 bytes from www.baidu.com (115.239.211.112): icmp_seq=1 ttl=128 time=8.04 ms 64 bytes from 115.239.211.112: icmp_seq=2 ttl=128 time=7.99 ms 64 bytes from 115.239.211.112: icmp_seq=3 ttl=128 time=8.50 ms 64 bytes from 115.239.211.112: icmp_seq=4 ttl=128 time=8.00 ms 64 bytes from 115.239.211.112: icmp_seq=5 ttl=128 time=7.89 ms
7. windows
C:\Users\Administrator>ping 192.168.178.133 正在 Ping 192.168.178.133 具有 32 字节的数据: 来自 192.168.178.133 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.178.133 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.178.133 的回复: 字节=32 时间<1ms TTL=64
配置成功。
关键一步是第4步的,建议二。