日期:2014-05-16  浏览次数:20600 次

程序员必知必会----linux常用命令之八【网络命令】

一.设置固定IP

先说一下临时设置IP的方法:

ifconfig eth0 192.168.12.51 #重启机器或者重启network马上失效

?

配置网卡的IP地址:

ifconfig eth0 192.168.0.1 netmask 255.255.255.0

配置网卡的子接口

ifconfig eth0:0 192.168.0.1 netmask 255.255.255.0

配置网卡的启用或禁用

ifconfig eth0 up ===?ifup eth0 ?#开启网卡

ifconfig eth0 down ===?ifdown eth0 #禁用网卡

?

?

永久设置:

1.设置IP地址、子网掩码

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

# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller

DEVICE=eth0

BOOTPROTO=static

HWADDR=00:15:F2:B9:92:4F

IPADDR=192.168.12.51

NETMASK=255.255.225.0

ONBOOT=yes

?

2.设置网关

vi /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=localhost.localdomain

GATEWAY=192.168.12.254

?

3.设置DNS

vi /etc/resolv.conf

; generated by /sbin/dhclient-script

nameserver 192.168.0.10

nameserver 202.106.0.20

?

4.重启网络

service network restart

?

二.iptables

1.查看:iptables -L -n

2.清空策略:iptables -F #临时的,重启防火墙就失效了

3.保存策略:service iptables save

?iptables详细说明参考:http://www.jb51.net/os/RedHat/1335.html

?

三.SELinux[没深入研究,直接关了]

1.查看:sestatus

2.关闭:

vi /etc/selinux/config?

SELINUX=disabled

重启服务器

?

四.查看占用端口

netstat -tunpl ??#查看全部占用端口的进程PID和进程名称

netstat -tunpl?| grep :80 ?#查看占用80端口的进程PID和进程名称

netstat -tunpl?| grep httpd ?#查看进程httpd占用的端口

?

netstat : 查看系统监听的端口, 显示网络连接信息

示例:

# netstat -tunpl?

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address ? ? ? ? ? ? ? Foreign Address ? ? ? ? ? ? State ? ? ? PID/Program name ??

tcp ? ? ? ?0 ? ? ?0 0.0.0.0:875 ? ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?2024/rpc.rquotad ? ?

tcp ? ? ? ?0 ? ? ?0 0.0.0.0:111 ? ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?1760/rpcbind ? ??

?