網絡管理

1. IP
1) 臨時設置

ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up

# 指定廣播
ifconfig eth0 210.34.6.89 netmask 255.255.255.128 broadcast 210.34.6.127

# 修改MAC地址
ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE

# 綁定多個IP地址,最多支持255個
ifconfig eth4:0 10.137.7.160 netmask 255.255.255.0 up 

# 添加或刪除IP地址
ip addr add 192.168.1.1/24 dev eth0
ip addr del 192.168.1.1/24 dev eth0

# 丟棄源地址屬於192.168.2.0/24網絡的所有數據報
ip rule add from 192.168.2.0/24 prio 32777 reject

2) 永久設置

vi /etc/sysconfig/network-scripts/ifcfg-eth0 (Rehat)
vi /etc/sysconfig/network/ifcfg-eth0 (Suse)
DEVICE=eth9
IPADDR=10.137.5.155
NETMASK=255.255.254.0
ONBOOT=yes
BOOTPROTO=static
GATEWAY=10.137.4.1

3) 重啓網絡

service network restart
/etc/init.d/network restart
ifdown eth0; ifup eth0
ifconfig eth0 down; ifconfig eth0 up

2. Gateway
1) 臨時設置

route add default gw 192.168.30.1 eth0
route del default gw 192.168.30.1 eth0

2) 永久設置

vi /etc/sysconfig/network (Rehat)
NETWORKING=yes
HOSTNAME=cbs5155
GATEWAY=10.137.4.1

vi /etc/sysconfig/network/routes (Suse)
default 10.186.18.1 - -

3. DNS

vi /etc/resolv.conf
nameserver 10.98.48.39
nameserver 10.72.255.100

4. 防火牆

service iptables start
service iptables stop

service iptables on
service iptables off

5. 修改主機名
1) Redhat

vi /etc/sysconfig/network
HOSTNAME=CentOS6.7

2) Suse

vi /etc/hostname
Suse11

/etc/rc.d/boot.localnet start

3) 臨時指定主機名

hostname Suse11
cat /proc/sys/kernel/hostname

4) IP與hostname映射關係(靜態路由表)

vi /etc/hosts
10.186.19.148 CentOS6.7
10.186.19.149 Suse11

6. 路由追蹤

traceroute 10.137.5.155

7. ip命令

ip addr
ip rule
ip neigh        # 只顯示有效的網卡
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章