本文详细介绍使用netcat命令网络同步复制系统
本记录思想是通过以太网络,配合简单的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?ive 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﹊ng 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.
作者:eexpress 责编:豆豆技术应用
正在加载评论...
- Linux/Unix新闻
- Linux/Unix入门
- Linux/Unix命令
- Linux/Unix安装
- Linux/Unix编程
- Linux/Unix管理
- Linux/Unix桌面
- Linux/Unix内核
- Linux/Unix软件
- Linux/Unix发行版
- redhat/Fedora
- Ubuntu Linux
- IBM AIX
- FreeBSD
- Solaris
- NetBSD
- SCO Unix
- find基本用法
- ldd命令原理及用法例子
- su和sudo命令的区别与使用技巧
- Linux操作系统下的dd命令技巧
- 关于Top命令的参数详解
- 关于Tar命令的使用
- SSH实用技巧及常用命令使用
- Linux后台执行命令
- VI命令使用技巧集锦
- Vmstat命令列出的属性详解
- 如何查看及修改文件读写权限
- 最大可存储的单文件容量
- ext2/ext3文件系统介绍
- 常用压缩格式的压缩解压方法
- Linux系统的引导过程详细解析
- Configure参数解释说明
- Linux下硬盘和分区的命名方法
- 硬链接与软链接的区别
- 权限和所有权模型
- 存储设备的两种表示方法