- vừa được xem lúc

Use SSH Port Forwarding to connect to resources (English)

0 0 9

Người đăng: Quân Huỳnh

Theo Viblo Asia

Bài viết tiếng Việt - Sử dụng SSH Port Forwarding để kết nối tới tài nguyên bị chặn

There are some cases where we need to connect to resources on the server, but for security reasons, those resources are on a server with a firewall or within a private network, so you can't connect to it. You can solve this problem by using a VPN or simply using SSH Port Forwarding.

Local Port Forward

The first use of SSH Port Forwarding is to use it to connect to resources on servers that have Firewall.

For example, we have a local code that needs to connect to the Redis on the server, but our server is blocked on port 6379 by the firewall, so from the outside, we cannot connect to it. We will use SSH Port Forwarding with the following syntax:

ssh -L localhost:<local-port>:localhost:<remote-address-port> <username>@<server-ip>

For example, the server has an IP of 172.168.65.117, and the username is ec2-user, in which there is a Redis child running at port 6379.

ssh -L localhost:6379:localhost:6379 ec2-user@172.168.65.117

You can remove localhost at the beginning.

ssh -L 6379:localhost:6379 ec2-user@172.168.65.117

At this time, we only need to connect to localhost:6379 to be able to access the Redis child on the server.

Bastion Host

The next use case of SSH Port Forwarding is to use it to connect to resources located in the Private Network.

We will encounter this case the most when we use the Cloud, for example with AWS we will create Amazon Relational Database Service (RDS) in a private network, of course, because the network is closed, we will not be able to connect to it. RDS from the outside, the common way people use it is to create a Bastion Host, and we will connect to RDS through this bastion host.

We will use SSH Port Forwarding with the following syntax:

ssh -L localhost:<local-port>:<remote-address>:<remote-address-port> <username>@<bastion-host-ip>

For example, with the bastion host with IP 172.168.65.117, the username of a bastion host is ec2-user, the address of RDS is postgres.123456789012.us-east-1.rds.amazonaws.com that running on port 5432.

ssh -L 5432:postgres.123456789012.us-east-1.rds.amazonaws.com:5432 ec2-user@172.168.65.117

At this point, we only need to connect to localhost:5432 to be able to access the RDS in the private network.

Conclusion

The above are two common use cases of SSH Port Forwarding, you can refer to other use cases here: SSH Port Forwarding - Why and How. Hope this article will be useful to you.

Bình luận

Bài viết tương tự

- vừa được xem lúc

Đề thi interview DevOps ở Châu Âu

Well. Chào mọi người, mình là Rice - một DevOps Engineers ở đâu đó tại Châu Âu.

0 0 66

- vừa được xem lúc

In calculus, love also means zero.

Mình nhớ hồi năm 2 đại học, thầy giáo môn calculus, trong một giây phút ngẫu hứng, đã đưa ra cái definition này. Lúc đấy mình cũng không nghĩ gì nhiều.

0 0 52

- vừa được xem lúc

Chuyện thay đổi

Thay đổi là một thứ gì đó luôn luôn đáng sợ. Cách đây vài tháng mình có duyên đi làm cho một banking solution tên là X.

0 0 31

- vừa được xem lúc

Pet vs Cattle - Thú cưng và gia súc

Khái niệm. Pets vs Cattle là một khái niệm cơ bản của DevOps. Bài viết này sẽ nói về sự phát triển của các mô hình dịch vụ từ cốt lõi Pets and Cattle. 1.

0 0 22

- vừa được xem lúc

Git workflow được Google và Facebook sử dụng có gì hay ho

Với developer thì Git hẳn là công cụ rất quen thuộc và không thể thiếu rồi. Thế nhưng có mấy ai thực sự hiểu được Git.

0 0 66

- vừa được xem lúc

Kubernetes - Học cách sử dụng Kubernetes Namespace cơ bản

Namespace trong Kubernetes là gì. Tại sao nên sử dụng namespace.

0 0 96