Linux修改网卡ens33为eth0以及centos7下修改动态IP为静态IP地址

时间:2018-08-30 20:03:50   收藏:0   阅读:1484
修改网卡ens33为eth0

在使用RHEL和Centos7,发现网卡名称变成了EnoX,挺不习惯。现更改回旧名称eth0看着顺眼。

1.备份/etc/sysconfig/grub文件

cp /etc/sysconfig/grub /etc/sysconfig/grub.bak

2.编辑/etc/sysconfig/grub文件

vim /etc/sysconfig/grub

在GRUB_CMDLINE_LINUX后的双引号内添加

net.ifnames=0 biosdevname=0

顺序无所谓,注意各参数间空格。
3.重建GRUB配置文件

grub2-mkconfig -o /boot/grub2/grub.cfg

4.备份网卡配置文件和更改网卡文件为eth0

cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0

ens33可能和各位不一样,具体先ifconfig查看自己的ensx多少。
5.编辑/etc/sysconfig/network-scripts/ifcfg-eth0文件

vim /etc/sysconfig/network-scripts/ifcfg-eth0

把NAME和DEVICE由原来的ens33更改为eth0即可。
6.重启系统即可。

[root@linfan ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:7b:4d:fb brd ff:ff:ff:ff:ff:ff
    inet 192.168.24.148/24 brd 192.168.24.255 scope global dynamic eth0
       valid_lft 1610sec preferred_lft 1610sec
    inet6 fe80::f395:669a:c751:9e90/64 scope link
       valid_lft forever preferred_lft forever

Linux下把动态Ip更改为静态Ip

我需要将ip修改为192.168.24.130

1.查看网关地址,我的是192.168.24.2

[root@linfan ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.24.2    0.0.0.0         UG    100    0        0 eth0
192.168.24.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0

2.查看DNS, 我的是192.168.24.2

[root@linfan ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.24.2

3.配置网卡信息,我的是 vi /etc/sysconfig/network-scripts/ifcfg-eth0

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0"
UUID="e7b272e4-cf09-46cb-8f85-ab6c9c469979"
DEVICE="eth0"
ONBOOT="yes"

需要更改的属性:
BOOTPROTO=”dhcp” 修改成 BOOTPROTO=”static”

需要添加的属性:
IPADDR0=192.168.24.130 # ip地址
PREFIXO0=24 #设置子网掩码
GATEWAY0=192.168.24.2 #设置网关
DNS1=8.8.8.8 #设置主DNS

修改后为

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO="static"
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=e7b272e4-cf09-46cb-8f85-ab6c9c469979
DEVICE=eth0
ONBOOT=yes
PREFIXO0=24
DNS0=8.8.8.8
IPADDR=192.168.24.130
PREFIX=24
GATEWAY=192.168.24.2

重启网卡

[root@linfan ~]# service network restart
Restarting network (via systemctl):                        [  OK  ]

验证:

ping www.baidu.com

[root@linfan ~]# ping www.baidu.com
PING www.a.shifen.com (119.75.216.20) 56(84) bytes of data.

查看ip


[root@linfan ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.24.130  netmask 255.255.255.0  broadcast 192.168.24.255
        inet6 fe80::f395:669a:c751:9e90  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:7b:4d:fb  txqueuelen 1000  (Ethernet)
        RX packets 3607  bytes 327107 (319.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2139  bytes 304955 (297.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!