首页 | 资讯动态 | linux基础 | 系统管理 | 网络管理 | 编程开发 | linux数据库 | linux相关 | linux认证 | 下载中心 | 专题
oklinux
 系统管理:中文环境 系统管理 桌面应用 内核技术 Linux基础:安装配置 常用命令 经验技巧 软件应用 Linux数据库:Mysql POSTGRE
 网络管理:网络安全 网络应用 Linux服务器 编程开发:PHP CC++ Python Perl SHELL 嵌入式开发 | PHP基础 PHP技巧 PHP应用 PHP文摘
 首页 linux资讯动态 Linux专题 | 其他Unix Linux解决方案 硬件相关 Linux认证 企业应用 Apache | 相关下载:资料 参考手册 服务器
 → 当前位置:首页>linux基础>常用命令>正文

使用netcat命令网络同步复制系统

OKLinux www.oklinux.cn 2007-01-05 来源:oklinux收集整理 会员收藏 游客收藏

    本记录思想是通过以太网络,配合简单的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(多数不要修改,除开目标机器有其他不同的系统), 然后就是显卡和声卡(这个我以前写过),硬件的驱动。
上一篇:菜鸟给grub设密码的简单快速方法   下一篇:Linux下常见文件解压方法及命令

收藏于收藏夹】 【评论】 【推荐】 【投稿】 【打印】 【关闭

相关文章
·Linux下常见文件解压方法及命令
·菜鸟给grub设密码的简单快速方法
·RedHat Linux 9键盘的快捷操作
·linux grep命令的使用
·用sort 和tsort 对文件进行排序
·用Linux Command Shell模拟DOS命令
·运用提示行命令让你在Linux下玩魔术
·浅谈FreeBSD 5.2常用操作的改变
·LINUX常用的系统状态查询命令
·Unix/BSD/Linux的口令机制初探
发表评论
密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。)
站内搜索
阅读排行榜
·ps命令常用用法
· Linux下如何删除非空目录
· date命令详解及ntp时间同
·新手从零开始:Linux系统
·Linux入门时必学60个文件
·Linux VI命令使用技巧集锦
·标准化您的 UNIX 命令行工
·Linux 笔记本基于“敲打”
·运用提示行命令让你在Linu
·常用的tar和rpm命令参数列
最新文章
·Linux操作系统PS命令详细
·教你使用Linux系统下的MAN
·Linux系统下Sudo命令的使
·Linux操作系统下打造友好
·Linux下Configure命令参数
·Linux操作系统下的一些简
·Fedora core Linux网络配
·Linux新手指南:关于Nmap
·Linux Shell脚本Ldd命令原
·定时自动运行任务的命令CR
·学习Linux操作系统的快捷
·su和sudo命令的区别与使用
·识别Linux系统的文件类型
·Linux系统下VI命令快捷键
·Linux操作系统下取得UUID

设为首页 - 加入收藏 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
Copyright © 2007 All rights reserved OKLinux.Cn 版权所有