天天看點

linux常用網絡設定

Linux常見網絡配置

<b>1.       </b><b>配置主機名</b>

[root@localhost ~]# vi /etc/sysconfig/network

NETWORKING_IPV6=no

HOSTNAME=localhost.localdomain 主機名

<b>2.       </b><b>檢視主機名</b>

[root@localhost ~]# hostname 顯示主機名

<b>3.       </b><b>設定ip</b>

Ifconfig 網卡名 ip位址 netmask 子網路遮罩

<b>檢視ip</b><b>位址</b>

[root@localhost ~]# ifconfig

eth0      Link encap:Ethernet HWaddr 00:0C:29:38:B4:2E 

          inet addr:192.168.1.101 Bcast:255.255.255.255 Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe38:b42e/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

          RX packets:1059 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1488 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:147694 (144.2 KiB) TX bytes:183032 (178.7 KiB)

          Interrupt:193 Base address:0x2000

lo        Link encap:Local Loopback 

          inet addr:127.0.0.1 Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING MTU:16436 Metric:1

          RX packets:1387 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1387 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:1788333 (1.7 MiB) TX bytes:1788333 (1.7 MiB)

You have new mail in /var/spool/mail/root

<b>設定虛拟機ip</b><b>位址</b>

 Ifconfig 網卡名:虛拟網卡名 ip位址 netmask 子網路遮罩

<b>啟用網卡和禁用網卡</b>

Ifconfig 網卡名稱 down 禁用網卡

Ifdown 網卡名

Ifconfig 網卡名稱 up    啟用網卡

Ifup    網卡名

<b>更改網卡MAC</b><b>位址</b>

Ifconfig 網卡名 down    先關閉網卡

Ifconfig 網卡名 hw ether mac位址     修改mac

Ifconfig 網卡名up

<b>4. 修改網關</b>

Route add default gw 網關ip位址       添加網關

Route del default gw 網關ip位址      删除網關

<b>5. 網卡配置檔案修改</b>

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 修改網卡參數

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

BOOTPROTO=dhcp   #啟用的dhcp,無法顯示ip

ONBOOT=yes

HWADDR=00:0c:29:38:b4:2e

TYPE=Ethernet

6.修改DNS

[root@localhost ~]# vi /etc/resolv.conf  

nameserver 202.96.134.133 #nameserver後面接dns位址

nameserver 202.96.128.68

7. 常用的網絡指令

Ping +可選參數 ip位址

[root@localhost ~]# ping 192.168.1.1

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.

64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=3.55 ms

64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=2.09 ms

64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=2.06 ms

測試網絡的連通性

Netstat

-r 顯示路由表

-a顯示所有連接配接資訊

-t顯示tcp資訊

-u顯示udp資訊

-c 持續顯示例如網絡狀态,監控連接配接情況

-s顯示網絡工作資訊統計表

Nslookup

Nslookup  ip位址    将ip位址解析域名

Nslookup 域名      将域名解析ip

繼續閱讀