歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 使用netcat命令網絡同步復制系統

使用netcat命令網絡同步復制系統

日期:2017/2/27 14:13:20   编辑:更多Linux
·系統提示“找不到網絡路徑”怎麼辦?·XP系統網絡優化六招簡單技巧·最常用的網絡命令精萃·深入掌握網絡加密及解密方法·網絡符號表情大全·制作一張含有網絡功能的dos啟動盤·虛擬網絡計算工具VNC使用指南·必學:電腦與網絡維護常用技巧·網絡路由安全攻防對策分析及實踐·常用網絡命令及命令實例詳解 本記錄思想是通過以太網絡,配合簡單的3個命令,實現把配置好了的完整系統復制到其他機器。以便於局域網上的快速安裝,並減少單台機器系統配置的過程。 使用了3個命令:nc,dump,restore。 代碼: netcat 簡稱 nc. Netcat 是一把非常簡單易用的基於 TCP/IP 協議(C/S模型的)的“瑞士軍刀”(man裡面,第一句就是這樣說的),它能允許我們通過網絡創建管道(pipe)。 dump 和 restore 是用於備份和恢復系統的常用命令。位於dump包中。可以apt-get install dump。 實驗的目的:我們將源機器的根分區,通過 dump/restore 和 nc 來傳送到目標機器的指定分區。 先實驗將源機器的/var/cache/apt/archives/復制到目標機器。 1:在接收端(目標電腦),創建一個 netcat 的監聽例程(-l),這個監聽例程將管道輸出到 restore。 把接受到的數據寫到目標機器。 nc -l -p 2000 -q 1 restore -r -f - 這裡-p是建立一個端口。-q 選項是讓 nc 在到達文件結束(EOF)時延時n秒後,自動停止運行。 2:在 源電腦, 創建另一個 netcat 的例程,這個例程將它從管道裡得到的輸入(也就是dump備份的數據)發給目標電腦。 dump -0 -f - /dir nc <target-ip> 2000 這裡 target-IP 是目標電腦的 IP 地址。 2000是端口號。 以下是man裡面的原版說明,可以參考。 代碼: restore說明: -f file Read the backup from file; file may be a special device file like /dev/st0 (a tape drive), /dev/sda1 (a disk drive), an ordinary file, or - (the standard input). If the name of the file isof the form host:file or user@host:file, restore reads from the named file on the remote host using rmt(8). -r Restore (rebuild) a file system. The target file system should be made pristine with mke2fs(8), mounted, and the user cd’d into the pristine file system before starting the restoration of the initial level 0 backup. If the level 0 restores sUCcessfully, the -r flag may be used to restore any necessary incremental backups on top of the level 0. The -r flag precludes an interac‐tive file extraction and can be detrimental to one’s health (not to mention the disk) if not used carefully. An example: mke2fs /dev/sda1 mount /dev/sda1 /mnt cd /mnt restore rf /dev/st0 Note that restore leaves a file restoresymtable in the root Directory to pass information between incremental restore passes. This file should be removed when the last incremental has been restored. 代碼: dump說明: -f file Write the backup to file; file may be a special device file like /dev/st0 (a tape drive), /dev/rsd1c (a floppy disk drive), an ordinary file, or - (the standard output). Multiple file names may be given as a single argument separated by commas. Each file will be used for one dump volume in the order listed; if the dump requires more volumes than the number of names given, the last file name will used for all remaining volumes after prompt‐ing for media changes. If the name of the file is of the form host:file or user@host:file dump writes to the named file on the remote host (which should already exist, dump doesn’t create a new remote file) using rmt(8). The default path name of the remote rmt(8) program is /etc/rmt; this can be overridden by the environment variable RMT. [-level#] 代碼: nc - TCP/IP swiss army knife說明: -l listen mode, for inbound connects -n numeric-only IP addresses, no DNS -o file hex dump of traffic -p port local port number (port numbers can be individual or ranges: lo-hi [inclusive]) -q seconds after EOF is detected, wait the specified number of seconds and then quit. ------------------------- 實驗結果,數據送傳可以,只是目標路徑有些偏差。2邊執行了 代碼: sudo dump -0 -f - /var/cache/apt/archives/ nc 10.23.1.100 2000 ~$ nc -l -p 2000 -q 1 restore -r -f - 結果數據全部傳送到了~/var/cache/apt/archives/。 當時考慮失誤,安裝目標機器系統時,圖簡單,安裝時選了格式全盤,安裝的server,然後安裝了dump包。結果搞得沒有空閒分區測試。直接根目錄對根目錄傳送,提示失敗,被中斷。想來也想得到。掛載了並且在運行中的根目錄怎麼會讓你覆蓋哦。 總體來說,實驗還是成功的。數據傳送正常。以後就只要找個帶了nc/dump/restore命令的live cd。就可以在裸機或者其他任何有空間的機器上,復制其他機器上配置好了的Linux系統了。我想以太網絡的速度應該比usb硬盤之類的要好得多。 省去了獨立安裝系統時,系統檢測,解包,下載包,配置軟件的時間,這些也是占用很長的時間的。 忘記了,復制以後,需要按照機器設置,修改/etc/fstab(分區結構), /etc/network/interfaces(網絡ip,dhcp的就可以不要修改), /boot/grub/menu.lst(多數不要修改,除開目標機器有其他不同的系統), 然後就是顯卡和聲卡(這個我以前寫過),硬件的驅動。




Copyright © Linux教程網 All Rights Reserved