一、将IP地址设置为固定值
1.进入到系统的IP地址保存文件所在目录
[root@localhost ~]# cd /etc/sysconfig/network-scripts
2.修改保存IP信息的文件
[root@localhost ~]# vim ifcfg-eth0 (你机器上的名字有可能不是这个,但是是以ifcfg-eth开头的文件)
保存后退出
3.重启网络
[root@localhost ~]# service network restart
注意:如果发现你的虚拟机连不上网,ping固定地址的时候出现:connect:Network is unreachable;而且使用以下命令查看ip时发现ip并不是你设置的固定值。
[root@localhost ~]# ip addr
则很有可能是因为本地的网卡没有启动。这时我们通过以下命令来启动网卡。
[root@localhost ~]# ifup eth0
其中eth0是我的网卡名称,你需要换成你自己的网卡名称。
二、关闭系统防火墙
说明:CentOS 7.0默认使用的是firewall作为防火墙,要想使用iptables必须重新设置一下。
1.关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service
2.禁止防火墙开机自启
[root@localhost ~]# systemctl disable firewalld.service
3.安装iptables service
[root@localhost ~]#
4.修改防火墙配置,如增加防火墙端口3306
[root@localhost ~]#
增加以下规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
保存退出后
重启防火墙使配置生效
[root@localhost ~]# systemctl restart iptables.service
设置防火墙开机启动
[root@localhost ~]# systemctl enable iptables.service
重启系统使设置生效
[root@localhost ~]# reboot
注意:mysql安装后,如果不关掉防火墙,则远程不能连接成功。