Linux中IP地址的配置

一、设置Linux的IP地址
1.搞懂三种网卡模式:桥接、NAT、仅单机模式
2.选择NAT模式
1).vi /etc/sysconfig/network-script/ifcfg-eth0设置成自动获得IP地址。

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

2).执行ip a或者ifconfig获取得到的IP地址,并route -n获得路由信息,得到网关

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.128.128
NETMASK=255.255.255.0
GATEWAY=192.168.128.2
DNS1=114.114.114.114

3).重启网卡service network restart

3.在ping www.baidu.com的时候发生Name or Service not know错误,经过排查
1).IP地址绑定主机名
cat /etc/hosts

192.168.128.128 Linux

2).cat /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=Linux
GATEWAY=192.168.128.2
NOZEROCONF=yes

3).添加DNS服务器
nameserver 114.114.114.114
nameserver 114.114.114.115

4).关闭防火墙
以下是Cetos 7之前的版本:
临时关闭
service iptables stop
永久关闭
chkconfig iptables off
查看防火墙状态
chkconfig --list|grep iptables

以下是Centos 7之后的版本

systemctl stop firewalld

systemctl status firewalld

systemctl disable firewalld

systemctl enable firewalld

systemctl start firewalld

5).关闭安全策略
查看
getenforce
设置
setenforce
永久关闭
vi /etc/selinux/config
SELINUX=disabled