唯一小编 发布时间:2019-03-12
1. 网卡配置文件
网卡配置文件一般是存放在/etc/sysconfig/network-scripts/下,名称一般为 ifcfg-eth0 ifcfg-eth1, ifcfg-em1 ifcfg-em2等,末尾数字根据网卡数量而定。
这里介绍其中比较重要的几参数:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #设备名称,也就是网卡名
ONBOOT=yes #如果是no那么重启网卡命令这个网卡是不启用的
BOOTPROTO=static #静态IP,还可以是dhcp,动态获取
IPADDR=192.168.1.189 #IP地址
PREFIX=24 #掩码的二进制1的数量,此行等同于NETMASK=255.255.255.0
GATEWAY=192.168.1.1 #网关
service network start #启用网卡
service network stop #关闭网上
service network restart #重启网卡
2. DNS设置
a) 添加DNS有两种方法,第一种是直接添加在网卡配置文件里
DEVICE=eth0 #设备名称,也就是网卡名
ONBOOT=yes #如果是no那么重启网卡命令这个网卡是不启用的
BOOTPROTO=static #静态IP,还可以是dhcp,动态获取
IPADDR=192.168.1.189 #IP地址
PREFIX=24 #掩码的二进制1的数量,此行等同于NETMASK=255.255.255.0
GATEWAY=192.168.1.1 #网关
DNS1=202.96.128.86 <===添加在此,但需要重启网卡才能生效
b) 第二种是添加在 /etc/resolv.conf
# vi /etc/resolv.conf
# Generated by NetworkManager
nameserver 202.96.128.86 #这行是添加DNS,保存后生效
3. 防火墙打开端口
防火墙配置文件默认是 /etc/sysconfig/iptables ,以下是默认配置
# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT #这是开放22端口
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
添加开放80、21、3306端口,输入以下命令
#/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp –dport 21 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp –dport 3306 -j ACCEPT
然后保存并重启防火墙:
# service iptables save
# service iptables restart
又或者直接修改/etc/sysconfig/iptables文件
# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT #这是开放22端口
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT #添加三行红字内容
-A INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
然后:wq保存并重启防火墙:
# service iptables restart
1. 网卡配置文件
网卡配置文件一般是存放在/etc/sysconfig/network-scripts/下,名称一般为 ifcfg-eth0 ifcfg-eth1, ifcfg-em1 ifcfg-em2等,末尾数字根据网卡数量而定。
这里介绍其中比较重要的几参数:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #设备名称,也就是网卡名
ONBOOT=yes #如果是no那么重启网卡命令这个网卡是不启用的
BOOTPROTO=static #静态IP,还可以是dhcp,动态获取
IPADDR=192.168.1.189 #IP地址
PREFIX=24 #掩码的二进制1的数量,此行等同于NETMASK=255.255.255.0
GATEWAY=192.168.1.1 #网关
service network start #启用网卡
service network stop #关闭网上
service network restart #重启网卡
2. DNS设置
a) 添加DNS有两种方法,第一种是直接添加在网卡配置文件里
DEVICE=eth0 #设备名称,也就是网卡名
ONBOOT=yes #如果是no那么重启网卡命令这个网卡是不启用的
BOOTPROTO=static #静态IP,还可以是dhcp,动态获取
IPADDR=192.168.1.189 #IP地址
PREFIX=24 #掩码的二进制1的数量,此行等同于NETMASK=255.255.255.0
GATEWAY=192.168.1.1 #网关
DNS1=202.96.128.86 <===添加在此,但需要重启网卡才能生效
b) 第二种是添加在 /etc/resolv.conf
# vi /etc/resolv.conf
# Generated by NetworkManager
nameserver 202.96.128.86 #这行是添加DNS,保存后生效
3. 防火墙打开端口
防火墙配置文件默认是 /etc/sysconfig/iptables ,以下是默认配置
# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT #这是开放22端口
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
添加开放80、21、3306端口,输入以下命令
#/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp –dport 21 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp –dport 3306 -j ACCEPT
然后保存并重启防火墙:
# service iptables save
# service iptables restart
又或者直接修改/etc/sysconfig/iptables文件
# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT #这是开放22端口
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT #添加三行红字内容
-A INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
然后:wq保存并重启防火墙:
# service iptables restart