CentOS7 configure static address, turn off firewall

CentOS7.2 set static ip

Find the configuration file first:

[ root@localhost bin]# cd /etc/sysconfig/network-scripts
[ root@localhost network-scripts]# ls
ifcfg-ens33  ifdown-ppp       ifup-ib      ifup-Team
ifcfg-lo           ifdown-routes    ifup-ippp    ifup-TeamPort
ifdown             ifdown-sit       ifup-ipv6    ifup-tunnel
ifdown-bnep        ifdown-Team      ifup-isdn    ifup-wireless
ifdown-eth         ifdown-TeamPort  ifup-plip    init.ipv6-global
ifdown-ib          ifdown-tunnel    ifup-plusb   network-functions
ifdown-ippp        ifup             ifup-post    network-functions-ipv6
ifdown-ipv6        ifup-aliases     ifup-ppp
ifdown-isdn        ifup-bnep        ifup-routes
ifdown-post        ifup-eth         ifup-sit
[ root@localhost network-scripts]# gedit ifcfg-ens33

The start configuration is:

TYPE="Ethernet"
BOOTPROTO="dhcp"
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="ens33"
UUID="157c8fb5-23b3-414c-8519-25bef9b20a54"
DEVICE="ens33"
ONBOOT="yes"

changed to:

TYPE="Ethernet"
# BOOTPROTO="dhcp"
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="ens33"
UUID="157c8fb5-23b3-414c-8519-25bef9b20a54"
DEVICE="ens33"
# ONBOOT="yes"

# static assignment
NM_CONTROLLED=no #Indicates that the interface will be set through the configuration file, rather than managed through the network manager
ONBOOT=yes #boot
BOOTPROTO=static #Static IP
IPADDR=192.168.1.122 #Local address
NETMASK=255.255.255.0 #Subnet mask
GATEWAY=192.168.1.1 #Default gateway

Modify /etc/sysconfig/network

# Created by anaconda
NETWORKING=yes
GATEWAY=192.168.1.1
DNS1=119.29.29.29
DNS2=182.254.116.116

Then restart the service##

service network restart

Generally this is fine, but if there is a problem, you must add HWADDR ## to the default file in network-scripts

[ root@localhost ~]# ip addr
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: eno16777736:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 link/ether 00:0c:29:a7:a0:8c brd ff:ff:ff:ff:ff:ff
 inet 192.168.1.104/24 brd 192.168.1.255 scope global dynamic eno16777736
  valid_lft 7141sec preferred_lft 7141sec
 inet 192.168.1.122/24 brd 192.168.1.255 scope global secondary eno16777736
  valid_lft forever preferred_lft forever
 inet6 fe80::ac30:2bcb:e910:3ae/64 scope link 
  valid_lft forever preferred_lft forever
3: virbr0:<NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
 link/ether 52:54:00:74:cb:1a 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 1000
 link/ether 52:54:00:74:cb:1a brd ff:ff:ff:ff:ff:ff

Check the specific link/ether first

And then assign it to ens33

such as:

TYPE="Ethernet"
# BOOTPROTO="dhcp"
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="157c8fb5-23b3-414c-8519-25bef9b20a54"
DEVICE="eno16777736"
# ONBOOT="yes"

# static assignment
NM_CONTROLLED=no #Indicates that the interface will be set through the configuration file, rather than managed through the network manager
ONBOOT=yes #boot
BOOTPROTO=static #Static IP
IPADDR=192.168.1.122 #Local address
NETMASK=255.255.255.0 #Subnet mask
GATEWAY=192.168.1.1 #Default gateway

HWADDR=00:0c:29:a7:a0:8c

Set the startup to start a service named NetworkManager-wait-online, the command is:

systemctl enable NetworkManager-wait-online.service

Restart the service.

=======================================================================

Wrong experience:

I mistakenly thought it was the bridge mode, and later found it was NAT, there was no virtual network editor for the virtual machine, pit!

changed to:

TYPE="Ethernet"
BOOTPROTO="static"
NM_CONTROLLED=no #Indicates that the interface will be set through the configuration file, rather than managed through the network manager

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="157c8fb5-23b3-414c-8519-25bef9b20a54"
DEVICE="eno16777736"
ONBOOT="yes" #The system will turn on the interface at startup.

IPADDR=192.168.1.122 #Static IP
GATEWAY=192.168.1.1 #Default gateway
NETMASK=255.255.255.0 #Subnet mask
# DNS1=192.168.7.1 #DNS configuration

Restart the network service:

service network restart
After restarting the network service, it is ok, but it still becomes dynamic after restarting the system.

[ root@localhost ~]# ip addr
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: eno16777736:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 link/ether 00:0c:29:a7:a0:8c brd ff:ff:ff:ff:ff:ff
 inet 192.168.1.104/24 brd 192.168.1.255 scope global dynamic eno16777736
  valid_lft 6995sec preferred_lft 6995sec
 inet 192.168.1.122/24 brd 192.168.1.255 scope global secondary eno16777736
  valid_lft forever preferred_lft forever
 inet6 fe80::9283:cd42:a281:7a9b/64 scope link 
  valid_lft forever preferred_lft forever
3: virbr0:<NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
 link/ether 52:54:00:74:cb:1a 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 1000
 link/ether 52:54:00:74:cb:1a brd ff:ff:ff:ff:ff:ff
[ root@localhost ~]# systemctl disable NetworkManager.service
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.[root@localhost ~]# chkconfig network on
[ root@localhost ~]# systemctl stop NetworkManager
[ root@localhost ~]# systemctl restart network

You can see the two ip from above

192.168.1.104

192.168.1.122

Solution:

systemctl disable NetworkManager.service`` chkconfig network on`` systemctl stop NetworkManager`` systemctl restart network
If it still appears

[ hongdada@localhost ~]$ systemctl status network.service
● network.service - LSB: Bring up/down networking
 Loaded:loaded(/etc/rc.d/init.d/network; bad; vendor preset: disabled)
 Active:failed(Result: exit-code)since day 2017-12-0323:05:01 CST; 2min 45s ago
  Docs: man:systemd-sysv-generator(8)
 Process:3957 ExecStart=/etc/rc.d/init.d/network start(code=exited, status=1/FAILURE)Dec 0323:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
12 Month 0323:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
12 Month 0323:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
12 Month 0323:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
12 Month 0323:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
12 Month 0323:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
12 Month 0323:05:01 localhost.localdomain systemd[1]: network.service: control process exited, code=exited status=112Month 0323:05:01 localhost.localdomain systemd[1]: Failed to start LSB: Bring up/down networking.12Month 0323:05:01 localhost.localdomain systemd[1]: Unit network.service entered failed state.12Month 0323:05:01 localhost.localdomain systemd[1]: network.service fail

Well. . .

View https://blog.csdn.net/kokuma/article/details/72876106

You can use the journal -xe to view the log, generally it is to modify the Name and DEVICE in the configuration file to ens33

First use ip addr to check the network card, and then check ifconfig

Generally, if it’s the first time, it’s not a clone, the network card name is eno16777736, here you just need to set a static ip, if it’s cloned, the network card name will be ens33 in the ip addr. In this case, we must also In the /etc/sysconfig/network-scripts/eno167777736 file, change the NAME and DEVICE to ens33, reset the static IP, and restart.

http://www.cnblogs.com/Leo_wl/p/5484136.html

http://www.bbsmax.com/A/n2d9D39v5D/

http://www.178linux.com/9928

Author: hongdada

Source: https://www.cnblogs.com/hongdada/p/6666932.html

In CentOS7, there are three defined hostnames:

Static (Static hostname)
The "static" hostname is also called the kernel hostname, which is the hostname that is automatically initialized from /etc/hostname when the system is started.

Transient (Tansient hostname)
A "transient" host name is a host name temporarily assigned while the system is running, for example, through a DHCP or mDNS server.

Flexible (Pretty hostname)
"Flexible" hostnames are also called "alias" hostnames.
"Flexible" hostnames allow free-form (including special/blank characters) hostnames to be displayed to end users (such as xh01@f5).
Both "static" hostnames and "transient" hostnames follow the same character restriction rules as Internet domain names.

In CentOS 7, there is a command line tool called hostnamectl, which allows you to view or modify the configuration related to the hostname.

View hostname:

//Check the current host name, check all three host names`hostnamectl`//Or, view all three hostnames`hostnamectl status`//Only view static, transient or flexible hostnames, use them separately--static,--transient or--pretty option[root@xh00 ~]# hostnamectl --static

xh00
[ root@xh00 ~]# hostnamectl --transient

xh01
[ root@xh00 ~]# hostnamectl --pretty

//Or, the view is transient (Tansient hostname)
hostname

//Or check the hostname configuration file, what you see is static (Static hostname)
cat /etc/hostname
View current Linux operating system related information (kernel version number, hardware architecture, host name, operating system type, etc.):

uname -a            //What you see is transient (Tansient hostname)
cat /etc/redhat-release     //View operating system environment

Modify the host name:
Method 1: Temporarily effective

hostname hostname//The host name that can only be modified temporarily, when the machine is restarted, the host name changes back.

hostname xh01

Method 2: Permanently effective

//Permanently modify the host name, and the modified name can be maintained after restart.
hostnamectl set-hostname xxx    

//Delete hostname
hostnamectl set-hostname ""
hostnamectl set-hostname ""--static
hostnamectl set-hostname ""--pretty
Modify all three hostnames: static, transient, and flexible hostnames:
[ root@localhost ~]# hostnamectl set-hostname xh00
[ root@localhost ~]# hostnamectl --pretty
[ root@localhost ~]# hostnamectl --static
xh00
[ root@localhost ~]# hostnamectl --transient
xh00
  As shown above, while modifying the static/When the host name is transient, any special characters or blank characters will be removed, and any uppercase letters in the provided parameters will be automatically converted to lowercase.
  Once the static hostname is modified,/etc/The hostname will be updated automatically. however,/etc/The hosts will not be updated to save the changes, so you must manually update each time you modify the host name/etc/hosts, and then restart CentOS 7. Otherwise, the system will be very slow when restarting.

Manual update/etc/hosts

vim /etc/hosts
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1 qqmm
#::1   localhost localhost.localdomain localhost6 localhost6.localdomain6
::1  qqmm

Restart CentOS 7
reboot -f
After restart

[ root@qqmm ~]# hostname
xh01
[ root@qqmm ~]# hostnamectl
xh01

xh01 If you only want to modify a specific hostname (static, transient or flexible), you can use the --static, --transient or --pretty option.
For example, to permanently modify the hostname, you can modify the static hostname:

 [ root@localhost ~]# hostnamectl --static set-hostname xh01
 After restarting CentOS 7

[ root@localhost ~]# hostnamectl --static
 xh01
 [ root@localhost ~]# hostnamectl --transient
 xh01
 [ root@localhost ~]# hostnamectl --pretty
 [ root@localhost ~]# hostname
 xh01

Actually, you don't need to restart the machine to activate permanent hostname modification. The above command will immediately modify the kernel hostname. After logging out and logging in again, prompt on the command line to observe the new static hostname

Reference article: https://www.jianshu.com/p/39d7000dfa47

Method 3: Permanently effective
Modify the configuration file /etc/hostname to modify the host name. Replace the name in the hostname name of the file content with the host name you want to restart.

vim /etc/hostname 
hostname  myname

or
Modify through nmtui, then restart hostnamed

nmcli general hostname servername
systemctl restart systemd-hostnamed

Original: https://blog.csdn.net/xuheng8600/article/details/79983927

Copyright: 可定博客© WNAG.COM.CN

Title of this article: ["CentOS7 configure a static address, turn off the firewall"] (https://wnag.com.cn/104.html)

Link to this article: https://wnag.com.cn/104.html

Special statement: Unless otherwise noted, the articles on this site are original. In principle, reprinting of articles on this site is prohibited. If you really want to reprint, please contact: [email protected], respect the achievements of others' labor, thanks~

Recommended Posts

CentOS7 configure static address, turn off firewall
Centos7 configure IP address
Configure static IP under CentOS 7
Turn off and turn on the firewall in ubuntu
Centos7 configure JDK
Configure Ocserv on CentOS 6
CentOS7 install iptables firewall
Ubuntu18.04, Centos7 static IP
Configure lamp under centos6.8
Centos7 configure nodejs environment
Configure CentOS7 GPU environment