Anchoring water heater flue? ? ?

Our gas water-heater is in the basement of a two-story house. The flue, a 4" galvinized pipe, goes directly into the brick chimney.
This seems to have become so loose it could just pull out.
How should I anchor this flue?
(We are getting our very old house ready for the market, so I'll be asking a lot of questions like this on this newsgroup in the coming days.)
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

With the proper flue mastic.

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Go to a heating/plumbing supply house (not HD) and get furnace cement. It's used exactly for that purpose............
message

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

HomeOwnersHub.com is a website for homeowners and building and maintenance pros. It is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.