JavaScript is required to for searching.
ナビゲーションリンクをスキップ
印刷ビューの終了
マニュアルページセクション 1: ユーザーコマンド     Oracle Solaris 11 Information Library (日本語)
search filter icon
search icon

ドキュメントの情報

はじめに

紹介

ユーザーコマンド

acctcom(1)

adb(1)

addbib(1)

admin(1)

alias(1)

allocate(1)

amt(1)

appcert(1)

apptrace(1)

apropos(1)

ar(1)

arch(1)

as(1)

asa(1)

at(1)

atq(1)

atrm(1)

audioconvert(1)

audioctl(1)

audioplay(1)

audiorecord(1)

audiotest(1)

auths(1)

auto_ef(1)

awk(1)

banner(1)

basename(1)

basename(1B)

batch(1)

bc(1)

bdiff(1)

bfs(1)

bg(1)

biff(1B)

break(1)

builtin(1)

cal(1)

calendar(1)

case(1)

cat(1)

cd(1)

cdc(1)

cdrw(1)

chdir(1)

checkeq(1)

checknr(1)

chgrp(1)

chkey(1)

chmod(1)

chown(1)

chown(1B)

ckdate(1)

ckgid(1)

ckint(1)

ckitem(1)

ckkeywd(1)

ckpath(1)

ckrange(1)

ckstr(1)

cksum(1)

cktime(1)

ckuid(1)

ckyorn(1)

clear(1)

cmp(1)

col(1)

comb(1)

comm(1)

command(1)

compress(1)

continue(1)

cp(1)

cpio(1)

cpp(1)

cputrack(1)

crle(1)

crontab(1)

csh(1)

csplit(1)

ct(1C)

ctags(1)

ctrun(1)

ctstat(1)

ctwatch(1)

cu(1C)

cut(1)

date(1)

dc(1)

deallocate(1)

decrypt(1)

delta(1)

deroff(1)

df(1B)

dhcpinfo(1)

diff(1)

diff3(1)

diffmk(1)

digest(1)

digestp(1)

dircmp(1)

dirname(1)

dirs(1)

dis(1)

disown(1)

dispgid(1)

dispuid(1)

dos2unix(1)

dpost(1)

du(1)

du(1B)

dump(1)

dumpcs(1)

dumpkeys(1)

echo(1)

echo(1B)

ed(1)

edit(1)

egrep(1)

eject(1)

elfdump(1)

elfedit(1)

elffile(1)

elfsign(1)

elfwrap(1)

encrypt(1)

enhance(1)

env(1)

eqn(1)

errange(1)

errdate(1)

errgid(1)

errint(1)

erritem(1)

error(1)

errpath(1)

errstr(1)

errtime(1)

erruid(1)

erryorn(1)

eval(1)

ex(1)

exec(1)

exit(1)

expand(1)

export(1)

exportfs(1B)

expr(1)

expr(1B)

exstr(1)

factor(1)

false(1)

fastboot(1B)

fasthalt(1B)

fc(1)

fg(1)

fgrep(1)

file(1)

file(1B)

filebench(1)

filep(1)

filesync(1)

filofaxp(1)

find(1)

finger(1)

fmt(1)

fmtmsg(1)

fold(1)

for(1)

foreach(1)

franklinp(1)

from(1B)

ftp(1)

function(1)

gcore(1)

gencat(1)

geniconvtbl(1)

genmsg(1)

get(1)

getconf(1)

getfacl(1)

getlabel(1)

getopt(1)

getoptcvt(1)

getopts(1)

gettext(1)

gettxt(1)

getzonepath(1)

glob(1)

goto(1)

gprof(1)

grep(1)

groups(1)

groups(1B)

grpck(1B)

hash(1)

hashcheck(1)

hashmake(1)

hashstat(1)

head(1)

helpdate(1)

helpgid(1)

helpint(1)

helpitem(1)

helppath(1)

helprange(1)

helpstr(1)

helptime(1)

helpuid(1)

helpyorn(1)

hist(1)

history(1)

hostid(1)

hostname(1)

i386(1)

i486(1)

iconv(1)

idnconv(1)

if(1)

indxbib(1)

install(1B)

ipcrm(1)

ipcs(1)

isainfo(1)

isalist(1)

jobs(1)

join(1)

jsh(1)

kbd(1)

kdestroy(1)

keylogin(1)

keylogout(1)

kill(1)

kinit(1)

klist(1)

kmdb(1)

kmfcfg(1)

kpasswd(1)

krb5-config(1)

ksh(1)

ksh88(1)

ksh93(1)

ktutil(1)

lari(1)

last(1)

lastcomm(1)

ld(1)

ldapadd(1)

ldapdelete(1)

ldaplist(1)

ldapmodify(1)

ldapmodrdn(1)

ldapsearch(1)

ldd(1)

ld.so.1(1)

let(1)

lex(1)

lgrpinfo(1)

limit(1)

line(1)

list_devices(1)

listusers(1)

llc2_autoconfig(1)

llc2_config(1)

llc2_stats(1)

ln(1)

ln(1B)

loadkeys(1)

locale(1)

localedef(1)

logger(1)

logger(1B)

login(1)

logname(1)

logout(1)

look(1)

lookbib(1)

lorder(1)

ls(1)

ls(1B)

m4(1)

mac(1)

mach(1)

machid(1)

madv.so.1(1)

mail(1)

Mail(1B)

mail(1B)

mailcompat(1)

mailp(1)

mailq(1)

mailstats(1)

mailx(1)

make(1S)

makekey(1)

man(1)

mconnect(1)

mcs(1)

mdb(1)

mesg(1)

mkdir(1)

mkmsgs(1)

mkstr(1B)

mktemp(1)

moe(1)

more(1)

mp(1)

mpss.so.1(1)

msgcc(1)

msgcpp(1)

msgcvt(1)

msgfmt(1)

msggen(1)

msgget(1)

mt(1)

mv(1)

nawk(1)

nc(1)

ncab2clf(1)

ncakmod(1)

neqn(1)

netcat(1)

newform(1)

newgrp(1)

newsp(1)

newtask(1)

nice(1)

nl(1)

nm(1)

nohup(1)

notify(1)

nroff(1)

od(1)

on(1)

onintr(1)

optisa(1)

pack(1)

page(1)

pagesize(1)

pam_tty_tickets.so(1)

pargs(1)

passwd(1)

paste(1)

patch(1)

pathchk(1)

pax(1)

pcat(1)

pcred(1)

perl(1)

pfbash(1)

pfcsh(1)

pfexec(1)

pfiles(1)

pfksh(1)

pflags(1)

pfsh(1)

pftcsh(1)

pfzsh(1)

pg(1)

pgrep(1)

pkcs11_inspect(1)

pkginfo(1)

pkgmk(1)

pkgparam(1)

pkgproto(1)

pkgtrans(1)

pkill(1)

pklogin_finder(1)

pktool(1)

plabel(1)

pldd(1)

plgrp(1)

plimit(1)

pmadvise(1)

pmap(1)

popd(1)

ppgsz(1)

ppriv(1)

pr(1)

praliases(1)

prctl(1)

preap(1)

print(1)

printenv(1B)

printf(1)

priocntl(1)

proc(1)

prof(1)

profiles(1)

projects(1)

prs(1)

prt(1)

prun(1)

ps(1)

ps(1B)

psig(1)

pstack(1)

pstop(1)

ptime(1)

ptree(1)

pushd(1)

pvs(1)

pwait(1)

pwd(1)

pwdx(1)

ranlib(1)

rcapstat(1)

rcp(1)

read(1)

readonly(1)

red(1)

refer(1)

regcmp(1)

rehash(1)

remote_shell(1)

remsh(1)

renice(1)

repeat(1)

reset(1B)

return(1)

rksh(1)

rksh88(1)

rlogin(1)

rm(1)

rmail(1)

rmdel(1)

rmdir(1)

rmformat(1)

rmmount(1)

rmumount(1)

roffbib(1)

roles(1)

rpcgen(1)

rpm2cpio(1)

rsh(1)

runat(1)

rup(1)

rup(1C)

ruptime(1)

rusage(1B)

rusers(1)

rwho(1)

sact(1)

sar(1)

sccs(1)

sccs-admin(1)

sccs-cdc(1)

sccs-comb(1)

sccs-delta(1)

sccsdiff(1)

sccs-get(1)

sccs-help(1)

sccshelp(1)

sccs-prs(1)

sccs-prt(1)

sccs-rmdel(1)

sccs-sact(1)

sccs-sccsdiff(1)

sccs-unget(1)

sccs-val(1)

scp(1)

script(1)

sdiff(1)

sed(1)

sed(1B)

select(1)

set(1)

setenv(1)

setfacl(1)

setlabel(1)

setpgrp(1)

settime(1)

sftp(1)

sh(1)

shcomp(1)

shell_builtins(1)

shift(1)

shutdown(1B)

size(1)

sleep(1)

soelim(1)

sort(1)

sortbib(1)

sotruss(1)

source(1)

sparc(1)

spell(1)

spellin(1)

split(1)

srchtxt(1)

ssh(1)

ssh-add(1)

ssh-agent(1)

ssh-http-proxy-connect(1)

ssh-keygen(1)

ssh-keyscan(1)

ssh-socks5-proxy-connect(1)

stop(1)

strchg(1)

strconf(1)

strings(1)

strip(1)

stty(1)

stty(1B)

sum(1)

sum(1B)

sun(1)

suspend(1)

svcprop(1)

svcs(1)

switch(1)

symorder(1)

sys-suspend(1)

sysV-make(1)

t300(1)

t300s(1)

t4014(1)

t450(1)

tabs(1)

tail(1)

talk(1)

tar(1)

tbl(1)

tcopy(1)

tee(1)

tek(1)

telnet(1)

test(1)

test(1B)

tftp(1)

time(1)

timemanp(1)

times(1)

timesysp(1)

timex(1)

tip(1)

touch(1)

touch(1B)

tplot(1)

tput(1)

tr(1)

tr(1B)

trap(1)

troff(1)

true(1)

truss(1)

tset(1B)

tsort(1)

tty(1)

type(1)

typeset(1)

ul(1)

ulimit(1)

umask(1)

unalias(1)

uname(1)

uncompress(1)

unexpand(1)

unget(1)

unhash(1)

unifdef(1)

uniq(1)

units(1)

unix2dos(1)

unlimit(1)

unpack(1)

unset(1)

unsetenv(1)

until(1)

updatehome(1)

uptime(1)

userattr(1)

users(1B)

uucp(1C)

uudecode(1C)

uuencode(1C)

uuglist(1C)

uulog(1C)

uuname(1C)

uupick(1C)

uustat(1C)

uuto(1C)

uux(1C)

vacation(1)

val(1)

valdate(1)

valgid(1)

valint(1)

valpath(1)

valrange(1)

valstr(1)

valtime(1)

valuid(1)

valyorn(1)

vc(1)

vedit(1)

ver(1)

vgrind(1)

vi(1)

view(1)

vipw(1B)

volcheck(1)

volrmmount(1)

w(1)

wait(1)

wc(1)

what(1)

whatis(1)

whence(1)

whereis(1B)

which(1)

while(1)

who(1)

whoami(1B)

whocalls(1)

whois(1)

write(1)

xargs(1)

xgettext(1)

xstr(1)

yacc(1)

yes(1)

ypmatch(1)

yppasswd(1)

ypwhich(1)

zcat(1)

zlogin(1)

zonename(1)

zonestat(1)

nc

, netcat

- arbitrary TCP and UDP connections and listens

形式

nc -h
nc [-46dnrtuvz] [-i interval] [-P proxy_username] [-p port] 
   [-s source_ip_address] [-T dspc] [-w timeout]
   [-X proxy_protocol] [-x proxy_address[:port]][-L timeout]
   [-e program] [-b bufsize] [-q timeout] [-m bytes]
   [-I bufsize][-O bufsize] hostname port_list
nc -l [-46DdEFnrtuvzZ] [-i interval] [-T dspc] [-e program]
   [-b bufsize] [-q timeout] [-R address/port[/proto]] [-m bytes]
   [-L timeout] [-I bufsize] [-O bufsize] [hostname] port
nc -l [-46DEFdnrtuvzZ] [-i interval] [-T dspc] [-e program]
   [-b bufsize] [-q timeout] [-R address/port[/proto]] [-m bytes]
   [-L timeout] [-I bufsize] [-O bufsize]
   -p port [hostname]
nc -U [-Ddtvz] [-i interval] [-w timeout] [-e program]
   [-b bufsize] [-q timeout] [-m bytes] path
nc -Ul [-46DdktvZ] [-i interval]  [-e program] [-b bufsize]
   [-q timeout] [-R address/port[/proto]] [-m bytes] path

機能説明

The nc (or netcat) utility is used for a variety of tasks associated with TCP or UDP. nc can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, perform port scanning, and deal with both IPv4 and IPv6. Unlike telnet(1), nc scripts nicely, and separates error messages onto standard error instead of sending them to standard output.

The nc command is often used for the following tasks:

The nc command can also be run as netcat, using the identical options.

オプション

The following options are supported:

-4

Force nc to use IPv4 addresses only.

-6

Force nc to use IPv6 addresses only.

-b bufsize

Specify buffer size for read operations.

The default value is 1024 bytes.

-D

Enable debugging on the socket.

-d

Do not attempt to read from stdin.

-E

Use exclusive bind for listening TCP or UDP socket.

It is an error to use this option without the -l option.

This option does not have any effect when used in conjunction with the -U option.

-e program

Execute external program after accepting a connection or making connection. Before the execution stdin,stdout,stderr is redirected to the network descriptor. Only one port can be used with this option.

It is an error to use this option in conjunction with the -R, -k, or -i options.

-F

Do not close network socket for writing after seeing EOF on stdin.

-h

Print nc help.

-I bufsize

Set receive (input) socket buffer size.

This option does not have any effect when used in conjunction with the -U option.

-i interval

Specify a delay time of interval between lines of text sent and received.

The interval is specified in seconds, with possible fractions.

This option also causes a delay time between connections to multiple ports, and therefore also affects port scan mode.

-k

Force nc to listen for another connection after its current connection is closed.

It is an error to use this option without the -l option.

It is an error to use this option in conjunction with the -e option.

L timeout

Linger on close - wait for messages to be sent after network descriptor is closed up to specified timeout in seconds.

-l

Listen for an incoming connection rather than initiate a connection to a remote host.

It is an error to use this option in conjunction with the -s or -z options.

If the -l option is used with a wildcard socket (no IP address or hostname specified) and without the -4 /-6 options, it accepts both IPv4 and IPv6 connections.

-m byte_count

Quit after receiving at least byte_count bytes. When used with -l option byte_count is compared to number of bytes received from the client.

byte_count must be greater than 0 and less than INT_MAX.

-N file

Specifies file with pattern for UDP port scanning. The contents of this file are used as payload for each emitted UDP packet.

It is an error to use this option without the -u and -z options.

-n

Do not do any naming or service lookups on any addresses, hostnames, or ports.

Use of this option means that hostname and port arguments are restricted to numeric values.

If used with -v option all addresses and ports are printed in numeric form, in addition to the restriction imposed on the arguments. This option does not have any effect when used in conjunction with the -U option.

-O bufsize

Set send (output) socket buffer size.

This option does not have any effect when used in conjunction with the -U option.

-P proxy_username

Specify a username (proxy_username) to present to a proxy server that requires authentication. If proxy_username is not specified, authentication is not attempted. Proxy authentication is only supported for HTTP CONNECT proxies at present.

It is an error to use this option in conjunction with the -l option.

-p port

When used without -l option, specify the source port nc should use, subject to privilege restrictions and availability. When used with the -l option, set the listen port.

This option can be used with -l option only provided global port argument is not specified.

-q timeout

After receiving EOF on stdin, wait for specified number of seconds and quit.

-R addr/port[/proto]

Perform port redirection to given host and port.

After the connection has been accepted, nc connects to the remote host/port and passes all data between the client and the remote host. The proto (protocol) part of the redirect specification can be either tcp or udp. If the proto is not specified, redirector uses the same protocol as the server.

It is an error to use this option in conjunction with the -z option.

-r

Choose destination ports randomly instead of sequentially within all ports specified by the port_listargument.

It is an error to use this option in conjunction with the -l option.

-s source_ip_address

Specify the IP of the interface which is used to send the packets.

It is an error to use this option in conjunction with the -l option.

-T dscp

Specify Differentiated Services Code Point for the connection.

For IPv4 this specifies the IP Type of Service (ToS) IP header field and the valid values for the argument are the string tokens: lowdelay, throughput, reliability, or an 8-bit hexadecimal value preceded by 0x.

For IPv6 (Traffic Class) only hexadecimal value can be used.

-t

Cause nc to send RFC 854 DON'T and WON'T responses to RFC 854 DO and WILL requests. This makes it possible to use nc to script telnet sessions.

-U

Specify the use of Unix Domain Sockets. If you specify this option without -l, nc, it becomes AF_UNIX client. If you specify this option with the -l option, a AF_UNIX server is created.

Use of this option requires that a single argument of a valid Unix domain path has to be provided to nc, not a host name or port.

-u

Use UDP instead of the default option of TCP.

-v

Specify verbose output.

-w timeout

Silently close the connection if a connection and stdin are idle for more than timeout seconds.

The default is no timeout.

This option has no effect on the connection establishment phase in client mode or waiting for a connection in server mode.

-X proxy_protocol

Use the specified protocol when talking to the proxy server. Supported protocols are 4 (SOCKS v.4), 5 (SOCKS v.5) and connect (HTTP proxy). If the protocol is not specified, SOCKS v. 5 is used.

It is an error to use this option in conjunction with the -l option.

-x proxy_address[:port]

Request connection to hostname using a proxy at proxy_address and port. If port is not specified, the well-known port for the proxy protocol is used (1080 for SOCKS, 3128 for HTTP).

It is an error to use this option in conjunction with the -l option.

This option does not work with numeric representation of IPv6 addresses.

-Z

In listening mode bind to address/port in all zones using the SO_ALLZONES socket option.

This option requires SYS_NET_CONFIG privilege.

-z

Perform port scan. For TCP ports (default), connect scan (full 3-way handshake) is tried with no data sent. For UDP (-u) empty UDP packets are sent by default. To specify UDP payload the -N option can be used.

The UDP scan mode is estimative, it considers a port to be open if it does not receive negative response (ICMP Destination Port Unreachable message). For this mode the timeout set with the -w option is used to wait for the ICMP messages or data from remote node. With -v any received data is dumped as hexadecimal bytes to stderr.

As most of the operating systems employ rate limiting for sending ICMP messages in reaction to input packets, it is necessary to use -i when performing UDP scan otherwise the results is not reliable.

It is an error to use this option in conjunction with the -l option.

オペランド

The following operands are supported:

hostname

Specify host name.

hostname can be a numerical IP address or a symbolic hostname (unless the -n option is specified).

In general, hostname must be specified, unless the -l option is given or -U is used (in which case the argument is a path). If hostname argument is specified with -l option then port argument must be given as well and nc tries to bind to that address and port. If hostname argument is not specified with -l option then nc tries to listen on a wildcard socket for given port.

path

Specify pathname.

port
port_list

Specify port.

port_list can be specified as single integers, ranges or combinations of both. Specify ranges in the form of nn-mm. The port_list must have at least one member, but can have multiple ports/ranges separated by commas.

In general, a destination port must be specified, unless the -U option is given, in which case a Unix Domain Socket path must be specified instead of hostname.

It is an error to use list of ports containing more than one port in conjunction with the -e option.

使用法

Client/Server Model

It is quite simple to build a very basic client/server model using nc. On one console, start nc listening on a specific port for a connection. For example, the command:

$ nc -l 1234

listens on port 1234 for a connection. On a second console (or a second machine), connect to the machine and port to which nc is listening:

$ nc 127.0.0.1 1234

There should now be a connection between the ports. Anything typed at the second console is concatenated to the first, and vice-versa. After the connection has been set up, nc does not really care which side is being used as a server and which side is being used as a client. The connection can be terminated using an EOF (Ctrl/d).

Data Transfer

The example in the previous section can be expanded to build a basic data transfer model. Any information input into one end of the connection is output to the other end, and input and output can be easily captured in order to emulate file transfer.

Start by using nc to listen on a specific port, with output captured into a file:

$ nc -l 1234 > filename.out

Using a second machine, connect to the listening nc process, feeding it the file which is to be transferred:

$ nc host.example.com 1234 < filename.in

After the file has been transferred, the connection closes automatically.

Talking to Servers

It is sometimes useful to talk to servers by hand rather than through a user interface. It can aid in troubleshooting, when it might be necessary to verify what data a server is sending in response to commands issued by the client.

For example, to retrieve the home page of a web site:

$ echo -n "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80

This also displays the headers sent by the web server. They can be filtered, if necessary, by using a tool such as sed(1).

More complicated examples can be built up when the user knows the format of requests required by the server. As another example, an email can be submitted to an SMTP server using:

$ nc localhost 25 << EOF
HELO host.example.com
MAIL FROM: <user@host.example.com
RCTP TO: <user2@host.example.com
DATA
Body of email.
.
QUIT
EOF

Port Scanning

It can be useful to know which ports are open and running services on a target machine. The -z flag can be used to tell nc to report open ports, rather than to initiate a connection.

In this example:

$ nc -z host.example.com 20-30
Connection to host.example.com 22 port [tcp/ssh] succeeded!
Connection to host.example.com 25 port [tcp/smtp] succeeded!

The port range was specified to limit the search to ports 20 - 30.

Alternatively, it might be useful to know which server software is running, and which versions. This information is often contained within the greeting banners. In order to retrieve these, it is necessary to first make a connection, and then break the connection when the banner has been retrieved. This can be accomplished by specifying a small timeout with the -w flag, or perhaps by issuing a QUIT command to the server:

$ echo "QUIT" | nc host.example.com 20-30
SSH-2.0-Sun_SSH_1.1
Protocol mismatch.
220 host.example.com IMS SMTP Receiver Version 0.84 Ready

inetd Capabilities

One of the possible uses is to create simple services by using inetd(1M).

The following example creates a redirect from TCP port 8080 to port 80 on host realwww:

# cat << EOF >> /etc/services
wwwredir    8080/tcp    # WWW redirect
EOF
# cat << EOF > /tmp/wwwredir.conf
wwwredir stream tcp nowait nobody /usr/bin/nc /usr/bin/nc -w 3 realwww 80
EOF
# inetconv -i /tmp/wwwredir.conf
wwwredir -> /var/svc/manifest/network/wwwredir-tcp.xml
Importing wwwredir-tcp.xml ...Done
# inetadm -l wwwredir/tcp
SCOPE    NAME=VALUE
name="wwwredir"
endpoint_type="stream"
proto="tcp"
isrpc=FALSE
wait=FALSE
exec="/usr/bin/nc -w 3 realwww 80"
arg0="/usr/bin/nc"
user="nobody"
default  bind_addr=""
default  bind_fail_max=-1
default  bind_fail_interval=-1
default  max_con_rate=-1
default  max_copies=-1
default  con_rate_offline=-1
default  failrate_cnt=40
default  failrate_interval=60
default  inherit_env=TRUE
default  tcp_trace=TRUE
default  tcp_wrappers=FALSE

Privileges

To bind to a privileged port number nc needs to be granted the net_privaddr privilege. If Solaris Trusted Extensions are configured and the port nc should listen on is configured as a multi-level port nc also needs the net_bindmlp privilege.

Privileges can be assigned to the user or role directly, by specifying them in the account's default privilege set in user_attr(4). However, this means that any application that this user or role starts have these additional privileges. To only grant the privileges(5) when nc is invoked, the recommended approach is to create and assign an rbac(5) rights profile. See EXAMPLES for additional information.

使用例

例 1 Using nc

Open a TCP connection to port 42 of host.example.com, using port 3141 as the source port, with a timeout of 5 seconds:

$ nc -p 3141 -w 5 host.example.com 42

Open a UDP connection to port 53 of host.example.com:

$ nc -u host.example.com 53

Open a TCP connection to port 42 of host.example.com using 10.1.2.3 as the IP for the local end of the connection:

$ nc -s 10.1.2.3 host.example.com 42

Use a list of ports and port ranges for a port scan on various ports:

$ nc -z host.example.com 21-25,53,80,110-120,443

Create and listen on a Unix Domain Socket:

$ nc -lU /var/tmp/dsocket

Create and listen on a UDP socket with associated port 8888:

$ nc -u -l -p 8888

which is the same as:

$ nc -u -l 8888

Create and listen on a TCP socket with associated port 2222 and bind to address 127.0.0.1 only:

$ nc -l 127.0.0.1 2222

Connect to TCP port, send some data and terminate the connection with TCP RST segment (instead of classic TCP closing handshake) by setting the linger option and timeout to 0:

$ echo "foo" | nc -L 0 host.example.com 22

Perform port redirection to port 22 on host host.example.com from local port 4545:

$ nc -R host.example.com/22 -l 4545

After that, it should be possible to run ssh(1) client and connect to host.example.com using host redir.example.com running the above command:

$ ssh -oStrictHostKeyChecking=no -p 4545 redir.example.com

It is also possible to let nc listen on TCP port and convert the TCP data stream to UDP (or vice versa):

$ nc -R host.example.com/53/udp -l 4666

Connect to port 42 of host.example.com using an HTTP proxy at 10.2.3.4, port 8080. This example could also be used by ssh(1). See the ProxyCommand directive in ssh_config(4) for more information.

$ nc -x10.2.3.4:8080 -Xconnect host.example.com 42

The same example again, this time enabling proxy authentication with username ruser if the proxy requires it:

$ nc -x10.2.3.4:8080 -Xconnect -Pruser host.example.com 42

Basic UDP port scan can be efficiently done like this:

$ nc -z -w 3 -u -i 0.5 host.example.com 11-100

Between each 2 ports it pauses for 0.5 second (thus evading ICMP message rate limiting) and waits up to 3 seconds for reply. If no reply comes then the port might be open.

To run nc with the smallest possible set of privileges as a user or role that has additional privileges (such as the default root account) it can be invoked using ppriv(1) as well. For example, limiting it to only run with the privilege to bind to a privileged port:

$ ppriv -e -sA=basic,!file_link_any,!proc_exec,!proc_fork,\
!proc_info,!proc_session,net_privaddr nc -l 42

To allow a user or role to use only nc with the net_privaddr privilege, a rights profile needs to be created:

/etc/security/exec_attr
Netcat privileged:solaris:cmd:::/usr/bin/nc:privs=net_privaddr

/etc/security/prof_attr
Netcat privileged:::Allow nc to bind to privileged ports:help=None.html

Assigning this rights profile using user_attr(4) permits the user or role to run nc allowing it to listen on any port. To permit a user or role to use nc only to listen on specific ports a wrapper script should be specified in the rights profiles:

/etc/security/exec_attr
Netcat restricted:solaris:cmd:::/usr/bin/nc-restricted:privs=net_privaddr

/etc/security/prof_attr
Netcat restricted:::Allow nc to bind to privileged ports:help=None.html

and write a shell script that restricts the permissible options, for example, one that permits one to bind only on ports between 42 and 64 (non-inclusive):

/usr/bin/nc-restricted:

#!/bin/sh
[ $# -eq 1 ] && [ $1 -gt 42 -a $1 -lt 64 ] && /usr/bin/nc -l -p "$1"

This grants the extra privileges when the user or role invokes nc using the wrapper script from a profile shell. See pfsh(1), pfksh(1), pfcsh(1), and pfexec(1).

Invoking nc directly does not run it with the additional privileges, and neither does invoking the script without using pfexec or a profile shell.

属性

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Availability
network/netcat
Interface Stability
See below.

The package name is Committed. The command line syntax is Committed for the -4, -6, -l, -n, -p, -u, and -w options and their arguments (if any). The name and port list arguments are Committed. The port range syntax is Uncommitted. The interface stability level for all other command line options and their arguments is Uncommitted.

関連項目

cat(1), pfcsh(1), pfexec(1), pfksh(1), pfsh(1), ppriv(1), sed(1), ssh(1), telnet(1), inetadm(1M), inetconv(1M), inetd(1M), ssh_config(4), user_attr(4), attributes(5), privileges(5), rbac(5)

Authors

The original implementation of nc was written by Hobbit, hobbit@avian.org.

nc was rewritten with IPv6 support by Eric Jackson, ericj@monkey.org.

注意事項

If an instance of nc is listening on a wildcard socket (regardless of address family specification) it is still possible to bind another nc process to concrete IP address and accept connections to this address. For example, with the following process running:

$ nc -4 -l 5656

it is possible to run another nc process listening on specific IP address and the same port:

$ nc -4 -l 10.20.30.40 5656

TCP connection to address 10.20.30.40 and port 5656 is accepted by the latter process, all TCP connections to port 5656 and different addresses is accepted by the former process.

Also, it is possible to steal IPv4 connections from a process which listens on a wildcard socket (without address family specification) by binding to IPv4 wildcard socket. To suppress this and the behavior described above the -E option could be used.