fedora配置ip

原创 2015年08月08日 14:36:01

在linux的世界里,给主机设置固定ip是这么做的(使用root用户):

1.查看要配的网络接口

用ifconfig查看查看在用的网卡接口,一般都用第一个如:eth0,en1,em1等

2.停用网络自动配置(如果有的话)

[html]view plaincopy

  1. systemctl stop NetworkManager.service

3.禁用网络自动配置(如果有的话)

[html]view plaincopy

  1. systemctl disable NetworkManager.service

4.写配置文件

[html]view plaincopy

  1. vi /etc/sysconfig/network-scripts/ifcfg-eth0(选择在用的网络接口,这里用第一个接口eth0)
写入内容:

[html]view plaincopy

  1. NM_CONTROLLED="yes"
  2. HWADDR="D8:D3:85:AE:DD:4C"
  3. BOOTPROTO="static" 设置为静态
  4. ONBOOT="yes" 设置为yes
  5. IPADDR=192.168.1.2 设置静态IP地址
  6. NETMASK=255.255.255.0 设置子网掩码
  7. BROADCAST=192.168.1.255 设置广播地址(可以不设)
  8. NETWORK=192.168.1.0 (可以不设)
  9. GATEWAY=192.168.1.1 设置网关

5.重启网络

[html]view plaincopy

  1. systemctl restart network.service

6.配置DNS

[html]view plaincopy

  1. sudo vi /etc/resolv.conf
写入内容:

[html]view plaincopy

  1. nameserver 192.168.1.1
  2. nameserver 8.8.8.8