您的位置:首页 > 运维架构 > Linux

Linux:网络配置

2017-02-10 01:38 141 查看
原文链接:http://www.cnblogs.com/Spiro-K/p/6384789.html

网络配置

 

 

1.网卡配置

vim /etc/sysconfig/network-scripts/ifcfg-eth0

1DEVICE=eth0
2 HWADDR=00:0C:29:93:41:2B
3 TYPE=Ethernet
4 UUID=d775c95a-a13d-4859-8460-0ff336f1f406
5 ONBOOT=yes        #开机自启
6 NM_CONTROLLED=yes
7 BOOTPROTO=static     #手动获取ip地址,如果自动改为BOOTPROTO=dhcp
8 GATEWAY=192.168.0.1
9 IPADDR=192.168.0.101
10 NETMASK=255.255.255.0
11 DNS1=192.168.1.1      #可添加多个DNS备用地址

 

2.DNS更改的配置文件

vim /etc/reslov.conf

1 # Generated by NetworkManager
2 nameserver 192.168.1.1

 

 3.重启网络

service network restart
正在关闭接口 eth0: 设备状态:3 (断开连接) [确定] 关闭环回接口: [确定] 弹出环回接口: [确定] 弹出界面 eth0: 活跃连接状态:激活中 活跃连接路径:/org/freedesktop/NetworkManager/ActiveConnection/1 状态:激活的 连接被激活 [确定

 

4.清除iptable

iptables -F       #清空iptable

/etc/init.d/iptables save    #保存

iptables:将防火墙规则保存到 /etc/sysconfig/iptables:     [确定]

 

 5.关闭selinux

vim /etc/selinux/config

1
2 # This file controls the state of SELinux on the system.
3 # SELINUX= can take one of these three values:
4 #     enforcing - SELinux security policy is enforced.
5 #     permissive - SELinux prints warnings instead of enforcing.
6 #     disabled - No SELinux policy is loaded.
7 SELINUX=disabled      #将selinux修改disable
8 # SELINUXTYPE= can take one of these two values:
9 #     targeted - Targeted processes are protected,
10 #     mls - Multi Level Security protection.
11 SELINUXTYPE=targeted

 

 6.网络配置常用命令

1)查看网卡与网线的连接情况

     mii-tool命令  http://www.cnblogs.com/Spiro-K/p/6384793.html

2)单网卡启动

ifconfig eth0 down

ifconfig eth0 up

 3)单网卡多IP配置

ifconfig eth0 : IP地址/掩码

ifconfig eth0 : IP地址/掩码

 

 4)主机名

查看
  hostname

临时更改
  hostname     name

写入配置文件
  vim /etc/sysconfig/network

 

5)DNS配置

DNS简易配置文件
vim /etc/hosts

DNS配置文件
vim /etc/resolv.conf

 

6)查看路由表

route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags      Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     #直连     1      0        0 eth0
0.0.0.0         192.168.0.1     0.0.0.0         UG   #网关     0      0        0 eth0

 

7)查看开启端口

netstat -antp
Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1444/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 1571/sshd tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 1960/sshd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1365/sshd tcp 0 0 192.168.0.101:22 192.168.0.100:55989 ESTABLISHED 1960/sshd tcp 0 0 192.168.0.101:22 192.168.0.100:52818 ESTABLISHED 1571/sshd tcp 0 0 ::1:25 :::* LISTEN 1444/master tcp 0 0 ::1:6010 :::* LISTEN 1571/sshd tcp 0 0 ::1:6011 :::* LISTEN 1960/sshd tcp 0 0 :::22 :::* LISTEN 1365/sshd

转载于:https://www.cnblogs.com/Spiro-K/p/6384789.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: