将linux系统的ip地址设置为静态
文章目录
将linux系统的ip地址设置为静态
Disable Network Manager
First stop and disable the gnome network manager from running on boot.
systemctl stop NetworkManagerservice systemctl disable NetworkManagerservice
Now start and enable the network service to run on boot.
systemctl restart networkservice systemctl enable networkservice
Set the Static Address
- Check which interface(s) you want to set as static.
root@server ifconfig
em1 flags192.1681.148 netmask 255.255255.0 broadcast 192.1681.255
inet6 fe80dd4c prefixlen scopeid ether d8 txqueuelen Ethernet
RX packets bytes 90374
RX errors dropped overruns frame
TX packets bytes 130252127.1
TX errors dropped overruns carrier collisions
device interrupt flags73mtu16436127.0 netmask 255.0
inet6 prefixlen scopeid
loop txqueuelen LocalLoopback
RX packets bytes
RX errors dropped overruns frame
TX packets bytes
TX errors dropped overruns carrier collisions
- Next edit the config file for the required interface.
sysconfignetworkscriptsifcfg
- Edit the config file to look similar to the following.
Change the BOOTPROTO from “dhcp” to “static”. Also adding IPADDR, NETMASK, BROADCAST and NETWORK variables and make sure ONBOOT is set to yes.
"e88f1292-1f87-4576-97aa-bb8b2be34bd3"
NM_CONTROLLED"yes"
HWADDR"D8:D3:85:AE:DD:4C"
BOOTPROTO"static"
DEVICE"em1"
ONBOOT"yes"
IPADDR192.168
NETMASK255.255255.0
BROADCAST192.1681.255
NETWORK192.168
GATEWAY192.168
Apply the Settings
Restart the network service to apply the settings.
systemctl restart networkservice
Configure DNS
Make sure the correct DNS servers are configured to allow Fedora to resolve domains.
resolv
nameserver 192.168
nameserver
遇到的问题
在进行 Disable Network Manager 操作的第二步restart时出现一个错误:
[root@aleks network-scripts]# systemctl restart network.service
Job failed. See system journal and 'systemctl status' for details.
出现这个问题的原因是:
网络配置器 em1 中的mac地址与硬件的mac地址不一样导致的
执行:
ip address show
与网络配置文件比较一下
sudo vi /etc/sysconfig/network-scripts/ifcfg-em1
如果不一样,将配置文件的的 HWADDR 项的值改成一样的
然后再执行,
ifup em1
好了以后再执行
systemctl restart networkservice
搞定。。。。。