CentOS自动获取ip和关闭防火墙

原创
2016/03/07 11:05
阅读数 185

一、自动获取IP的方法:


1、/ etc/sysconfig/network-scripts/ifcfg-eth0

[root@smbserver ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 

DEVICE=eth0    //由eth0来启动

HWADDR=00:0C:29:40:EC:61    //MAC地址

TYPE=Ethernet

UUID=9c6a7fc6-66ce-406d-993f-6ab26a730e72

ONBOOT=yes         //系统启动时网络接口是否有效

NM_CONTROLLED=yes

BOOTPROTO=dhcp  //获取IP方式,static是固定IP,none是手动,dhcp是自动获取


2、/etc/sysconfig/network

[root@smbserver ~]# cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=smbserver


3、/etc/hosts

[root@smbserver ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


4、/etc/resolv.conf

[root@smbserver ~]# cat /etc/resolv.conf 

# Generated by NetworkManager

nameserver 202.96.128.86

nameserver 8.8.8.8


二、手动设置IP、DNS

手动设定IP、DNS只需要修改三个文件就可以了

1、/etc/sysconfig/network

[zhangy@localhost  network-scripts]$ cat /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=yes

#HOSTNAME=localhost.localdomain        //为什么要把主机名注释掉,一般先解析主机名或者域名,再解析DNS

GATEWAY=192.168.1.1                            //加上网关


2、/etc/sysconfig/network-scripts/ifcfg-eth0

[zhangy@localhost network-scripts]$ cat ifcfg-eth0

# Marvell Technology Group Ltd. 88E8039 PCI-E Fast Ethernet Controller

DEVICE=eth0

BOOTPROTO=none                         //启动为手动

BROADCAST=192.168.1.255

HWADDR=00:16:D3:A2:F6:09

IPADDR=192.168.1.108                   //设置的IP

NETMASK=255.255.255.0                //子网掩码

NETWORK=192.168.1.0

IPV6INIT=yes

IPV6_AUTOCONF=yes

ONBOOT=yes

TYPE=Ethernet                                //网络类型


3、/etc/resolv.conf

[zhangy@localhost network-scripts]$ cat /etc/resolv.conf

#; generated by /sbin/dhclient-script

#nameserver 192.168.1.1

#search localdomain

nameserver 116.228.111.118             //加上主DNS

nameserver 180.168.255.18              //加上次DNS


centos 7:

systemctl stop firewalld.service #停止

systemctl disable firewalld.service #禁用

之前的版本:

service iptables stop #停止

chkconfig iptables off #禁用

/etc/rc.d/init.d/iptables stop

关闭命令:  service iptables stop 

 永久关闭防火墙:chkconfig iptables off

两个命令同时运行,运行完成后查看防火墙关闭状态 

   service iptables status


展开阅读全文
打赏
1
4 收藏
分享
加载中
更多评论
打赏
0 评论
4 收藏
1
分享
返回顶部
顶部