[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"content:legacy:page:\u002Fposts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1":3,"content:legacy:navigation":340,"content:legacy:surround:\u002Fposts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1":625,"content:related-articles:What is the difference between localhost and 127.0.0.1?":628},{"id":4,"title":5,"aside":6,"body":7,"categories":6,"category":323,"description":324,"duration":325,"extension":326,"footer":6,"header":6,"icon":6,"image":327,"main":6,"meta":330,"navigation":6,"path":331,"publishedAt":332,"seo":333,"sitemap":334,"stem":335,"tags":336,"toc":6,"top":338,"__hash__":339},"content\u002Fposts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1.md","What is the difference between localhost and 127.0.0.1?",null,{"type":8,"value":9,"toc":317},"minimark",[10,15,37,44,55,59,70,81,84,87,97,102,106,115,143,150,155,165,171,180,188,191,206,213,237,240,273,276,307,310],[11,12,14],"h2",{"id":13},"currently-viewing","Currently viewing",[16,17,18,19,28,29,32,33,36],"p",{},"Surely those who work in the profession are very familiar with the scene of debugging code locally. Type npm run and the browser will automatically open a website, and the address bar will show something like ",[20,21,22],"strong",{},[23,24,27],"a",{"rel":25},[26],"nofollow","http:\u002F\u002Flocalhost:xxx\u002Findex.html",". Many people just use it like that without really paying attention to the difference between ",[20,30,31],{},"localhost"," and ",[20,34,35],{},"127.0.0.1",". Those who work in infrastructure can still grasp it, but many Devs do not clearly distinguish between these two, so those who do not know can read this.",[16,38,39],{},[40,41],"img",{"alt":42,"src":43},"","https:\u002F\u002Fdevops.vn\u002Fuploads\u002Fimages\u002F2025\u002F08\u002F8cb15d3c-2344-4961-9c40-9b3fa7289853.webp",[16,45,18,46,28,51,32,53,36],{},[20,47,48],{},[23,49,27],{"rel":50},[26],[20,52,31],{},[20,54,35],{},[11,56,58],{"id":57},"from-domain-to-program-how-does-it-work","From Domain to Program: How Does It Work?",[16,60,61,62,65,66,69],{},"To really understand localhost, I need to talk a little about how users access a program through a domain. Take an example. When people type google.com into their browser, the first thing it does is ask the ",[20,63,64],{},"DNS (Domain Name System)"," what the ",[20,67,68],{},"IP address of google.com"," is.",[16,71,72,73,76,77,80],{},"Why do we need an ",[20,74,75],{},"IP address","? Imagine this: when someone sends a package to your company, the shipping form will have the company address, company name, and recipient name. The delivery person will rely on the address to find the way. In the online world, the domain name ",[20,78,79],{},"(google.com)"," is like the company name, while the IP address is the physical address. To find the right program, you need an IP address.\nDNS is like a giant phone book, listing the corresponding IP address for each domain name. After people buy a domain name, the provider will help register the domain name and the server's IP address into this DNS.",[16,82,83],{},"With the IP address, the browser will send a request to that address. This request is packaged by the operating system and transmitted over the network. Routers on the internet will rely on this IP address to find the path and finally send the packet to the correct computer holding that IP.",[16,85,86],{},"A computer can run many network programs. So how can the request be sent to the correct application? This is where ports come into play. Each network program can \"listen\" on one or more ports, and the system will not allow two programs to occupy the same port. When sending a request, I specify an additional port so that it goes to the correct program.",[16,88,89,90,32,93,96],{},"But why don't I need to type the port when I go to Google? That's because there are default ports: ",[20,91,92],{},"80 for HTTP",[20,94,95],{},"443 for HTTPS",". When I don't specify a port, the browser will use these ports automatically.",[16,98,99],{},[40,100],{"alt":42,"src":101},"https:\u002F\u002Fdevops.vn\u002Fuploads\u002Fimages\u002F2025\u002F08\u002Fe9fce02d-fa6d-4de0-ba7f-255fa0075e32.webp",[11,103,105],{"id":104},"vậy-localhost-và-127001-khác-nhau-chỗ-nào","Vậy Localhost và 127.0.0.1 khác nhau chỗ nào?",[107,108,109],"ul",{},[110,111,112],"li",{},[20,113,114],{},"1. What is Localhost?",[16,116,117,120,121,127,128,131,132,135,136,139,140,142],{},[20,118,119],{},"Localhost"," is a ",[20,122,123],{},[124,125,126],"code",{},"domain name",". Basically, it is no different from ",[20,129,130],{},"google.com"," or other domains that people often access, except that it is more special and easier to remember. The scope of localhost is limited to the computer that everyone is using. Both Mr. ",[20,133,134],{},"A"," and Mr. ",[20,137,138],{},"B"," can use ",[20,141,31],{}," on their computers without touching each other, each person will access the website on their own computer.",[107,144,145],{},[110,146,147],{},[20,148,149],{},"2. What is 127.0.0.1?",[16,151,152,154],{},[20,153,35],{}," is an IP address. Specifically, it is a special IP address, called a loopback address, used to refer to the current computer itself. People can use this IP address even when the computer is not connected to the internet, which is very convenient for developing and testing programs. Your debug programs are running and \"listening\" on this IP address.",[16,156,157,160,161,164],{},[124,158,159],{},"So how is localhost resolved to **127.0.0.1**? Do you need to ask DNS?"," - ",[124,162,163],{},"No",".",[16,166,167,168,170],{},"This resolution is handled right on each person's computer. On every computer, there is a file called hosts, this file contains a few hardcoded DNS resolution rules. In which, the default rule is to resolve localhost to ",[20,169,35],{},". This is a common convention.",[16,172,173,174,176,177,179],{},"If you like, you can edit the hosts file to give it a different name, for example maycuatoi, and point it to ",[20,175,35],{},". You can even point google.com to ",[20,178,35],{},", but it only works on your computer, not on anyone else.",[16,181,182,160,185],{},[124,183,184],{},"Running multiple websites on the same IP and Port",[124,186,187],{},"Different network programs cannot share the same port, but there are ways to get around the rules.",[16,189,190],{},"In the old days, virtual host providers could cram dozens or hundreds of websites on the same physical server, and everyone accessed their site through the default port 80. How did they do that?",[16,192,193,194,197,198,201,202,205],{},"If you have ever worked with a web server like ",[20,195,196],{},"Nginx",", ",[20,199,200],{},"Apache",", or ",[20,203,204],{},"IIS",", you will be familiar with the concept of a host header. The host header is essentially a domain. By setting the host header, programs can share the same network port.",[107,207,208],{},[110,209,210],{},[20,211,212],{},"3. How it works",[16,214,215,216,219,220,222,223,225,226,229,230,233,234,236],{},"When starting, Nginx will take over port ",[20,217,218],{},"80"," for itself.\nWhen a website request arrives at Nginx's port ",[20,221,218],{},", it will look at the domain in the request (which is the host header).\nBased on this domain, Nginx will know which website this request is for that has been configured in it.\nNginx will then forward the request to the corresponding web.\nPrivate IP Address\nIn addition to ",[20,224,35],{},", there are many other private IP addresses, such as the very familiar ",[20,227,228],{},"192.168.x.x"," range. These IP addresses are reserved for use in the internal network (LAN). Your company can use the address ",[20,231,232],{},"192.168.1.1",", and my company can also use ",[20,235,232],{}," without conflict.",[16,238,239],{},"Common private IP ranges of IPv4 include:",[107,241,242,253,263],{},[110,243,244,249,250],{},[20,245,246],{},[124,247,248],{},"Class A:"," ",[124,251,252],{},"10.0.0.0 to 10.255.255.255",[110,254,255,249,260],{},[20,256,257],{},[124,258,259],{},"Class B:",[124,261,262],{},"172.16.0.0 to 172.31.255.255",[110,264,265,249,270],{},[20,266,267],{},[124,268,269],{},"Class C:",[124,271,272],{},"192.168.0.0 to 192.168.255.255",[16,274,275],{},"There are also some other reserved IP ranges:",[107,277,278,298],{},[110,279,280,281,284,285,288,289,291,292,295,296,164],{},"The range ",[20,282,283],{},"127.0.0.0"," to ",[20,286,287],{},"127.255.255.255"," is used for loopback testing, which includes the address ",[20,290,35],{},". People assigning themselves the IP ",[20,293,294],{},"127.0.0.2"," will work exactly the same as ",[20,297,35],{},[110,299,280,300,284,303,306],{},[20,301,302],{},"169.254.0.0",[20,304,305],{},"169.254.255.255"," is used when the computer is not connected to the LAN and cannot receive an IP from the DHCP server.\nAbout IPv6",[16,308,309],{},"Everyone may have heard of IPv6, which was introduced because the IPv4 address space was exhausted. In theory, IPv6 can assign an IP address to every grain of sand on Earth. Although it has been talked about for many years, IPv4 is still more popular for many reasons.",[16,311,312,313,316],{},"An IPv6 address looks like this: ",[20,314,315],{},"2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b",". It is 128 bits long, much longer than IPv4's 32 bits.",{"title":42,"searchDepth":318,"depth":318,"links":319},2,[320,321,322],{"id":13,"depth":318,"text":14},{"id":57,"depth":318,"text":58},{"id":104,"depth":318,"text":105},"tutorial","Introduction to the concepts of localhost and 127.0.0.1 in networking",6,"md",{"src":328,"alt":329},"https:\u002F\u002Fi.ytimg.com\u002Fvi\u002F91PrPbuHdhg\u002Fmaxresdefault.jpg","localhost_and_127.0.0.1_image",{},"\u002Fposts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1","2025-08-29",{"title":5,"description":324},{"loc":331,"lastmod":332},"posts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1",[323,337],"network",false,"67SOBvRjZYm56CDdSLyQ0qqgn7R1MpHK-RvE7AHxn-g",[341,457,465,604],{"title":342,"icon":343,"path":344,"stem":345,"children":346,"page":338},"Cheatsheets","fluent-color:paw-16","\u002Fcheatsheets","cheatsheets",[347,352,357,362,367,372,377,382,387,392,397,402,407,412,417,422,427,432,437,442,447,452],{"title":348,"path":349,"stem":350,"icon":351},"Bash","\u002Fcheatsheets\u002Fbash","cheatsheets\u002Fbash","material-icon-theme:powershell",{"title":353,"path":354,"stem":355,"icon":356},"CSS","\u002Fcheatsheets\u002Fcss","cheatsheets\u002Fcss","vscode-icons:file-type-css2",{"title":358,"path":359,"stem":360,"icon":361},"Docker","\u002Fcheatsheets\u002Fdocker","cheatsheets\u002Fdocker","vscode-icons:file-type-docker2",{"title":363,"path":364,"stem":365,"icon":366},"Git","\u002Fcheatsheets\u002Fgit","cheatsheets\u002Fgit","devicon:git",{"title":368,"path":369,"stem":370,"icon":371},"Golang","\u002Fcheatsheets\u002Fgo","cheatsheets\u002Fgo","material-icon-theme:go",{"title":373,"path":374,"stem":375,"icon":376},"HTML","\u002Fcheatsheets\u002Fhtml","cheatsheets\u002Fhtml","material-icon-theme:html",{"title":378,"path":379,"stem":380,"icon":381},"JavaScript","\u002Fcheatsheets\u002Fjavascript","cheatsheets\u002Fjavascript","material-icon-theme:javascript",{"title":383,"path":384,"stem":385,"icon":386},"Latex","\u002Fcheatsheets\u002Flatex","cheatsheets\u002Flatex","material-icon-theme:latexmk",{"title":388,"path":389,"stem":390,"icon":391},"Linux","\u002Fcheatsheets\u002Flinux","cheatsheets\u002Flinux","devicon:linux",{"title":393,"path":394,"stem":395,"icon":396},"Markdown","\u002Fcheatsheets\u002Fmarkdown","cheatsheets\u002Fmarkdown","material-icon-theme:markdown",{"title":398,"path":399,"stem":400,"icon":401},"Mongo","\u002Fcheatsheets\u002Fmongo","cheatsheets\u002Fmongo","devicon:mongodb",{"title":403,"path":404,"stem":405,"icon":406},"Nest","\u002Fcheatsheets\u002Fnest","cheatsheets\u002Fnest","material-icon-theme:nest",{"title":408,"path":409,"stem":410,"icon":411},"Next","\u002Fcheatsheets\u002Fnext","cheatsheets\u002Fnext","logos:nextjs-icon",{"title":413,"path":414,"stem":415,"icon":416},"Node","\u002Fcheatsheets\u002Fnode","cheatsheets\u002Fnode","material-icon-theme:nodejs",{"title":418,"path":419,"stem":420,"icon":421},"Nuxt","\u002Fcheatsheets\u002Fnuxt","cheatsheets\u002Fnuxt","material-icon-theme:nuxt",{"title":423,"path":424,"stem":425,"icon":426},"React","\u002Fcheatsheets\u002Freact","cheatsheets\u002Freact","material-icon-theme:react",{"title":428,"path":429,"stem":430,"icon":431},"Redis","\u002Fcheatsheets\u002Fredis","cheatsheets\u002Fredis","vscode-icons:folder-type-redis-opened",{"title":433,"path":434,"stem":435,"icon":436},"SQL","\u002Fcheatsheets\u002Fsql","cheatsheets\u002Fsql","material-icon-theme:database",{"title":438,"path":439,"stem":440,"icon":441},"Typescript","\u002Fcheatsheets\u002Ftypescript","cheatsheets\u002Ftypescript","material-icon-theme:typescript",{"title":443,"path":444,"stem":445,"icon":446},"Vercel","\u002Fcheatsheets\u002Fvercel","cheatsheets\u002Fvercel","vscode-icons:file-type-light-vercel",{"title":448,"path":449,"stem":450,"icon":451},"Vue","\u002Fcheatsheets\u002Fvue","cheatsheets\u002Fvue","material-icon-theme:vue",{"title":453,"path":454,"stem":455,"icon":456},"Windows","\u002Fcheatsheets\u002Fwindow","cheatsheets\u002Fwindow","material-icon-theme:folder-windows",{"title":458,"icon":343,"path":459,"stem":460,"children":461,"page":338},"Interviews","\u002Finterviews","interviews",[462],{"title":373,"path":463,"stem":464,"icon":376},"\u002Finterviews\u002Fhtml","interviews\u002Fhtml",{"title":466,"icon":467,"path":468,"stem":469,"children":470,"page":338},"Posts","fluent-color:data-bar-vertical-ascending-24","\u002Fposts","posts",[471,480,496,522,530,543,552,561,571,594],{"title":472,"icon":436,"redirect":473,"path":474,"stem":475,"children":476,"page":338},"Database","\u002Fposts\u002Fdatabase\u002Freplication-strategy","\u002Fposts\u002Fdatabase","posts\u002Fdatabase",[477],{"title":478,"path":473,"stem":479,"icon":6},"Database Replication strategy in large systems","posts\u002Fdatabase\u002Freplication-strategy",{"title":358,"icon":361,"redirect":481,"path":482,"stem":483,"children":484,"page":338},"\u002Fposts\u002Fdocker\u002Fdocker-commands","\u002Fposts\u002Fdocker","posts\u002Fdocker",[485,488,492],{"title":486,"path":481,"stem":487,"icon":6},"Docker commands essentials","posts\u002Fdocker\u002Fdocker-commands",{"title":489,"path":490,"stem":491,"icon":6},"Some useful Dockerfile templates","\u002Fposts\u002Fdocker\u002Fdockerfile-templates","posts\u002Fdocker\u002Fdockerfile-templates",{"title":493,"path":494,"stem":495,"icon":6},"Setup Docker environment on Windows","\u002Fposts\u002Fdocker\u002Fsetup-docker-on-window","posts\u002Fdocker\u002Fsetup-docker-on-window",{"title":497,"icon":498,"redirect":499,"path":500,"stem":501,"children":502,"page":338},"Git & GitHub","material-icon-theme:git","\u002Fposts\u002Fgit\u002Fbrightly-decorate-graph","\u002Fposts\u002Fgit","posts\u002Fgit",[503,506,510,514,518],{"title":504,"path":499,"stem":505,"icon":6},"Brightly decorate your GitHub Graph","posts\u002Fgit\u002Fbrightly-decorate-graph",{"title":507,"path":508,"stem":509,"icon":6},"Download a specific folder on GitHub repository","\u002Fposts\u002Fgit\u002Fdownload-specific-folder","posts\u002Fgit\u002Fdownload-specific-folder",{"title":511,"path":512,"stem":513,"icon":6},"Syncing Git Tags across to other repositories","\u002Fposts\u002Fgit\u002Fsyncing-tags-across-repositories","posts\u002Fgit\u002Fsyncing-tags-across-repositories",{"title":515,"path":516,"stem":517,"icon":6},"Unlocking GitHub Achievement badges","\u002Fposts\u002Fgit\u002Funlocking-achievement-badges","posts\u002Fgit\u002Funlocking-achievement-badges",{"title":519,"path":520,"stem":521,"icon":6},"Essential Git commands every developer should master","\u002Fposts\u002Fgit\u002Fuseful-commands-like-pro","posts\u002Fgit\u002Fuseful-commands-like-pro",{"title":368,"icon":371,"redirect":523,"path":524,"stem":525,"children":526,"page":338},"\u002Fposts\u002Fgolang\u002Foptimizing-performance-with-pgo","\u002Fposts\u002Fgolang","posts\u002Fgolang",[527],{"title":528,"path":523,"stem":529,"icon":6},"Optimizing Performance in Go Applications with PGO","posts\u002Fgolang\u002Foptimizing-performance-with-pgo",{"title":378,"icon":531,"redirect":532,"path":533,"stem":534,"children":535,"page":338},"vscode-icons:file-type-js","\u002Fposts\u002Fjavascript\u002F9-lines-of-tips","\u002Fposts\u002Fjavascript","posts\u002Fjavascript",[536,539],{"title":537,"path":532,"stem":538,"icon":6},"9 lines of JavaScript replace 50 lines of code","posts\u002Fjavascript\u002F9-lines-of-tips",{"title":540,"path":541,"stem":542,"icon":6},"Javascript Promises - Specific functions and use cases","\u002Fposts\u002Fjavascript\u002Fpromises-cheatsheet","posts\u002Fjavascript\u002Fpromises-cheatsheet",{"title":413,"icon":544,"redirect":545,"path":546,"stem":547,"children":548,"page":338},"material-icon-theme:nodejs-alt","\u002Fposts\u002Fnodejs\u002Fevent-loop","\u002Fposts\u002Fnodejs","posts\u002Fnodejs",[549],{"title":550,"path":545,"stem":551,"icon":6},"Secret about Event Loop flow in Nodejs","posts\u002Fnodejs\u002Fevent-loop",{"title":418,"icon":553,"redirect":554,"path":555,"stem":556,"children":557,"page":338},"vscode-icons:file-type-nuxt","\u002Fposts\u002Fnuxt\u002Fenable-pwa-in-nuxt","\u002Fposts\u002Fnuxt","posts\u002Fnuxt",[558],{"title":559,"path":554,"stem":560,"icon":6},"Enable PWA and Service Worker in Nuxt","posts\u002Fnuxt\u002Fenable-pwa-in-nuxt",{"title":562,"icon":563,"redirect":564,"path":565,"stem":566,"children":567,"page":338},"Performance","emojione:rocket","\u002Fposts\u002Fperformance\u002Fbackground-image-injection-problem","\u002Fposts\u002Fperformance","posts\u002Fperformance",[568],{"title":569,"path":564,"stem":570,"icon":6},"Background-Image injection problem in UX","posts\u002Fperformance\u002Fbackground-image-injection-problem",{"title":572,"icon":573,"redirect":574,"path":575,"stem":576,"children":577,"page":338},"Tutorial","fluent-color:book-open-lightbulb-24","\u002Fposts\u002Ftutorial\u002Fclassification-and-functionality-of-the-servers","\u002Fposts\u002Ftutorial","posts\u002Ftutorial",[578,581,582,586,590],{"title":579,"path":574,"stem":580,"icon":6},"Classification and functionality of the servers","posts\u002Ftutorial\u002Fclassification-and-functionality-of-the-servers",{"title":5,"path":331,"stem":335,"icon":6},{"title":583,"path":584,"stem":585,"icon":6},"8 essential network protocols every programmer should know","\u002Fposts\u002Ftutorial\u002Fessential-network-protocols","posts\u002Ftutorial\u002Fessential-network-protocols",{"title":587,"path":588,"stem":589,"icon":6},"Pre rels in header link tag - SEO technique enhancement","\u002Fposts\u002Ftutorial\u002Fpre-rels-in-header-link-tag","posts\u002Ftutorial\u002Fpre-rels-in-header-link-tag",{"title":591,"path":592,"stem":593,"icon":6},"Better code with SOLID principles","\u002Fposts\u002Ftutorial\u002Fwhat-is-solid","posts\u002Ftutorial\u002Fwhat-is-solid",{"title":595,"icon":596,"redirect":597,"path":598,"stem":599,"children":600,"page":338},"UI\u002FUX","devicon:figma","\u002Fposts\u002Fuiux\u002Fcommon-button-mistake","\u002Fposts\u002Fuiux","posts\u002Fuiux",[601],{"title":602,"path":597,"stem":603,"icon":6},"Common Button Mistake in UI\u002FUX","posts\u002Fuiux\u002Fcommon-button-mistake",{"title":605,"icon":606,"path":607,"stem":608,"children":609,"page":338},"Templates","fluent-color:data-pie-24","\u002Ftemplates","templates",[610,613,616,619,622],{"title":368,"path":611,"stem":612,"icon":371},"\u002Ftemplates\u002Fgo","templates\u002Fgo",{"title":408,"path":614,"stem":615,"icon":411},"\u002Ftemplates\u002Fnext","templates\u002Fnext",{"title":418,"path":617,"stem":618,"icon":421},"\u002Ftemplates\u002Fnuxt","templates\u002Fnuxt",{"title":423,"path":620,"stem":621,"icon":426},"\u002Ftemplates\u002Freact","templates\u002Freact",{"title":448,"path":623,"stem":624,"icon":451},"\u002Ftemplates\u002Fvue","templates\u002Fvue",[626,627],{"title":579,"path":574,"stem":580,"children":-1},{"title":583,"path":584,"stem":585,"children":-1},[629,637],{"_path":584,"title":583,"description":630,"image":631,"category":323,"tags":634,"duration":635,"publishedAt":636},"What are network protocols? Explore the functions and use cases of each type of network protocol in digital communication",{"src":632,"alt":633},"https:\u002F\u002Fraw.githubusercontent.com\u002Ffullstack-core\u002Fblog\u002Frefs\u002Fheads\u002Fmain\u002Fblog\u002Fcover\u002F8-essential-network-protocols-every-programmer-should-know.webp","Protocols image",[323,337],7,"2025-06-16",{"_path":574,"title":579,"description":638,"image":639,"category":323,"tags":642,"duration":635,"publishedAt":643},"What is server? Functions of popular servers nowadays.",{"src":640,"alt":641},"https:\u002F\u002Fraw.githubusercontent.com\u002Ffullstack-core\u002Fblog\u002Frefs\u002Fheads\u002Fmain\u002Fblog\u002Fcover\u002Fclassification-and-functionality-of-the-servers.webp","Server image",[323,337],"2025-02-26"]