Linux modified Nic Ens33 for eth0 and Centos7 dynamic IP as static IP address

Source: Internet
Author: User

Modify the NIC Ens33 to Eth0

In the use of Rhel and CENTOS7, found that the NIC name became Enox, quite unaccustomed. Now change back to the old name Eth0 looked pleasing to the eye.

1. Back up the/etc/sysconfig/grub file

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

2. Edit the/etc/sysconfig/grub file

vim /etc/sysconfig/grub

Add inside double quotes after grub_cmdline_linux

net.ifnames=0 biosdevname=0

The order does not matter, note the space between the parameters.
3. Rebuilding the Grub configuration file

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

4. Back up the NIC configuration file and change the NIC file to Eth0

cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bakmv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0

Ens33 may not be the same as you, the specific first ifconfig to see their own ensx how much.
5. Edit the/etc/sysconfig/network-scripts/ifcfg-eth0 file

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

Change the name and device from the original ens33 to eth0.
6. Reboot the system.

[[email protected] ~]# ip a1: 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 forever2: 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
Change dynamic IP to static IP under Linux

I need to change IP to 192.168.24.130

1. View the gateway address, mine is 192.168.24.2

[[email protected] ~]# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         192.168.24.2    0.0.0.0         UG    100    0        0 eth0192.168.24.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0

2. View DNS, mine is 192.168.24.2

[[email protected] ~]# cat /etc/resolv.conf# Generated by NetworkManagersearch localdomainnameserver 192.168.24.2

3. Configure the NIC information, mine is 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"

Properties that need to be changed:
Bootproto= "DHCP" modified to bootproto= "static"

Properties to add:
IPADDR0=192.168.24.130 # IP Address
Prefixo0=24 #设置子网掩码
gateway0=192.168.24.2 #设置网关
dns1=8.8.8.8 #设置主DNS

After modification to

TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO="static"DEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=eth0UUID=e7b272e4-cf09-46cb-8f85-ab6c9c469979DEVICE=eth0ONBOOT=yesPREFIXO0=24DNS0=8.8.8.8IPADDR=192.168.24.130PREFIX=24GATEWAY=192.168.24.2

Restart the NIC

[[email protected] ~]# service network restartRestarting network (via systemctl):                        [  OK  ]
Verify:

Ping www.baidu.com

[[email protected] ~]# ping www.baidu.comPING www.a.shifen.com (119.75.216.20) 56(84) bytes of data.

View IP

[[email protected] ~]# ifconfig eth0eth0: 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

Linux modified Nic Ens33 for eth0 and Centos7 dynamic IP as static IP address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.