標籤:
請教一個關於網路設定的問題,
該網路連接圖形介面中 有2個配置,其中System eth0 有對應的設定檔/etc/sysconfig/network-scripts/ifcfg-eth0,但是zhoucf這個配置是我手工在圖形介面裡添加的,它的對應的設定檔在哪裡呢? 我想在初始化linux有個純淨的網路設定,用命令列刪除上面圖中zhoucf配置 怎麼辦呢? -----------------------------
find /root -type f -name "*" | xargs grep "zhoucf"
找到/root/.gconf/system/networking/connections/2/connection/%gconf.xml: <stringvalue>zhoucf22</stringvalue>/root/.gconf/system/networking/connections/1/connection/%gconf.xml: <stringvalue>zhoucf</stringvalue>
路徑中的數字1和2分別代表第1個和第2個手工配置的網路設定, 進入檔案夾1,ll顯示內容如下:[[email protected] Desktop]# cd /root/.gconf/system/networking/connections/1
[[email protected] 1]# ll
total 16
drwx------. 2 root root 4096 Sep 7 17:11 802-3-ethernet
drwx------. 2 root root 4096 Sep 7 17:11 connection
-rw-------. 1 root root 0 Sep 7 16:48 %gconf.xml
drwx------. 2 root root 4096 Sep 7 17:11 ipv4
drwx------. 2 root root 4096 Sep 7 17:11 ipv6 其中
connection/%gconf.xml中配置了連結的名稱id、uuid、type等內容,內容如下:Xml代碼
- <?xml version="1.0"?>
- <gconf>
- <entry name="timestamp" mtime="1410081115" type="string">
- <stringvalue>1410081115</stringvalue>
- </entry>
- <entry name="type" mtime="1410081115" type="string">
- <stringvalue>802-3-ethernet</stringvalue>
- </entry>
- <entry name="uuid" mtime="1410081115" type="string">
- <stringvalue>c0a50c06-f281-48ca-b1d5-6499ffb98b48</stringvalue>
- </entry>
- <entry name="id" mtime="1410081115" type="string">
- <stringvalue>zhoucf</stringvalue>
- </entry>
- <entry name="name" mtime="1410081115" type="string">
- <stringvalue>connection</stringvalue>
- </entry>
- </gconf>
ipv4/
/%gconf.xml 中配置了ip地址、dns等內容,其中地址以ip倒序的數值形式表示Xml代碼
- <?xml version="1.0"?>
- <gconf>
- <entry name="routes" mtime="1410081115" type="list" ltype="int">
- </entry>
- <entry name="address-labels" mtime="1410081115" type="list" ltype="string">
- <li type="string">
- <stringvalue></stringvalue>
- </li>
- </entry>
- <entry name="addresses" mtime="1410081115" type="list" ltype="int">
- <li type="int" value="-939415360"/>
- <li type="int" value="24"/>
- <li type="int" value="16885952"/>
- </entry>
- <entry name="dns" mtime="1410081115" type="list" ltype="int">
- <li type="int" value="16885952"/>
- </entry>
- <entry name="method" mtime="1410081115" type="string">
- <stringvalue>manual</stringvalue>
- </entry>
- <entry name="name" mtime="1410081115" type="string">
- <stringvalue>ipv4</stringvalue>
- </entry>
- </gconf>
java 計算代碼:Java代碼
- public class IpLong {
- /**
- * ip地址轉成整數.
- * @param ip
- * @return
- */
- public static long ip2long(String ip) {
- String[] ips = ip.split("[.]");
- long num = 16777216L*Long.parseLong(ips[0]) + 65536L*Long.parseLong(ips[1]) + 256*Long.parseLong(ips[2]) + Long.parseLong(ips[3]);
- return num;
- }
-
- /**
- * 整數轉成ip地址.
- * @param ipLong
- * @return
- */
- public static String long2ip(long ipLong) {
- //long ipLong = 1037591503;
- long mask[] = {0x000000FF,0x0000FF00,0x00FF0000,0xFF000000};
- long num = 0;
- StringBuffer ipInfo = new StringBuffer();
- for(int i=0;i<4;i++){
- num = (ipLong & mask[i])>>(i*8);
- if(i>0) ipInfo.insert(0,".");
- ipInfo.insert(0,Long.toString(num,10));
- }
- return ipInfo.toString();
- }
- public static void main(String[] args) {
- //System.out.println(ip2long("219.239.110.138"));
- System.out.println(ip2long("192.168.1.200"));//3232235976
- System.out.println(ip2long("200.1.168.192"));//3355551936
- System.out.println(long2ip(16885952));//16885952 在ipv4//%gconf.xml中 dns的配置
- //列印結果:-56.1.168.192
- System.out.println(long2ip(-939415360));//939415360 在ipv4//%gconf.xml中 addresses的配置
- //列印結果 -56.1.168.192 (其中 256-56=200) 通過計算得到200.1.168.192
-
- }
- }
總結:
1、配置linuxip的時候,設定ifcfg-eh0就行了,這是系統層級的,在圖形介面手工配置的ip設定,是使用者層級的,且重啟後,系統會優先載入系統層級的配置
2、在分析過程中尋找命令功不可沒:
grep "zhoucf" -rl /root
和
find /root -type f -name "*" | xargs grep "zhoucf"
3、知道了NetworkManager 是怎麼存放ip配置的,就可以放心配置ifcfg-ech0來配置網路設定了
centos6.5圖形介面NetworkManager 配置ip檔案位置